gt:             content = new LazyHtml(editProfileView.render(form, form2));
context: package org.iatoki.judgels.jophiel.controllers;
  
  import com.google.common.collect.ImmutableList;
  import org.apache.commons.io.FilenameUtils;
  import org.iatoki.judgels.play.IdentityUtils;
  import org.iatoki.judgels.play.InternalLink;
  import org.iatoki.judgels.play.LazyHtml;
  import org.iatoki.judgels.play.controllers.AbstractJudgelsController;
  import org.iatoki.judgels.play.views.html.layouts.centerLayout;
  import org.iatoki.judgels.play.views.html.layouts.headingLayout;
  import org.iatoki.judgels.play.views.html.layouts.tabLayout;
  import org.iatoki.judgels.jophiel.UserInfo;
  import org.iatoki.judgels.jophiel.forms.UserProfileForm;
  import org.iatoki.judgels.jophiel.forms.UserProfilePictureForm;
  import org.iatoki.judgels.jophiel.controllers.securities.Authenticated;
  import org.iatoki.judgels.jophiel.controllers.securities.Authorized;
  import org.iatoki.judgels.jophiel.controllers.securities.HasRole;
  import org.iatoki.judgels.jophiel.controllers.securities.LoggedIn;
  import org.iatoki.judgels.jophiel.services.UserActivityService;
  import org.iatoki.judgels.jophiel.services.UserProfileService;
  import org.iatoki.judgels.jophiel.services.UserService;
  import org.iatoki.judgels.jophiel.views.html.profile.editProfileView;
  import org.iatoki.judgels.jophiel.views.html.profile.serviceEditProfileView;
  import org.iatoki.judgels.jophiel.views.html.profile.viewProfileView;
  import play.Logger;
  import play.data.Form;
  import play.db.jpa.Transactional;
  import play.i18n.Messages;
  import play.mvc.BodyParser;
  import play.mvc.Http;
  import play.mvc.Result;
  
  import javax.inject.Inject;
  import javax.inject.Named;
  import javax.inject.Singleton;
  import java.io.IOException;
  import java.net.MalformedURLException;
  import java.net.URL;
  
  @Singleton
  @Named
  public final class UserProfileController extends AbstractJudgelsController {
  
      private final UserService userService;
      private final UserProfileService userProfileService;
      private final UserActivityService userActivityService;
  
      @Inject
      public UserProfileController(UserService userService, UserProfileService userProfileService, UserActivityService userActivityService) {
          this.userService = userService;
          this.userProfileService = userProfileService;
          this.userActivityService = userActivityService;
      }
  
      @Authenticated(value = {LoggedIn.class, HasRole.class})
      @Transactional
      public Result profile() {
          return serviceProfile(null);
      }
  
      @Authenticated(value = {LoggedIn.class, HasRole.class})
      @Transactional
      public Result postProfile() {
          return postServiceProfile(null);
      }
  
      @Authenticated({LoggedIn.class, HasRole.class})
      @Authorized("admin")
      @Transactional
      public Result viewProfile(String username) {
          if (userService.existByUsername(username)) {
              UserInfo user = userService.findUserByUsername(username);
  
              LazyHtml content = new LazyHtml(viewProfileView.render(user));
              if (IdentityUtils.getUserJid() != null) {
                  content.appendLayout(c -> tabLayout.render(ImmutableList.of(new InternalLink(Messages.get("profile.profile"), routes.UserProfileController.viewProfile(username)), new InternalLink(Messages.get("profile.activities"), routes.UserActivityController.viewUserActivities(username))), c));
                  content.appendLayout(c -> headingLayout.render(user.getUsername(), c));
                  ControllerUtils.getInstance().appendSidebarLayout(content);
                  ControllerUtils.getInstance().appendBreadcrumbsLayout(content, ImmutableList.of(
                          new InternalLink(Messages.get("profile.profile"), routes.UserProfileController.viewProfile(username))
                  ));
              } else {
                  content.appendLayout(c -> headingLayout.render(user.getUsername(), c));
                  content.appendLayout(c -> centerLayout.render(c));
              }
              ControllerUtils.getInstance().appendTemplateLayout(content, "Profile");
  
              ControllerUtils.getInstance().addActivityLog(userActivityService, "View user profile " + user.getUsername() + " <a href=\"" + "http://" + Http.Context.current().request().host() + Http.Context.current().request().uri() + "\">link</a>.");
  
              return ControllerUtils.getInstance().lazyOk(content);
          } else {
              return notFound();
          }
      }
  
      @BodyParser.Of(value = BodyParser.MultipartFormData.class, maxLength = (2 << 20))
      @Authenticated(value = {LoggedIn.class, HasRole.class})
      @Transactional
      public Result postAvatar() {
          return postServiceAvatar(null);
      }
  
      @Authenticated(value = {LoggedIn.class, HasRole.class})
      @Transactional
      public Result serviceProfile(String continueUrl) {
          Form<UserProfileForm> form = Form.form(UserProfileForm.class);
          Form<UserProfilePictureForm> form2 = Form.form(UserProfilePictureForm.class);
  
          UserInfo user = userService.findUserByUserJid(IdentityUtils.getUserJid());
          UserProfileForm userProfileForm = new UserProfileForm();
          userProfileForm.name = user.getName();
  
          form = form.fill(userProfileForm);
  
          ControllerUtils.getInstance().addActivityLog(userActivityService, "Try to update profile <a href=\"" + "http://" + Http.Context.current().request().host() + Http.Context.current().request().uri() + "\">link</a>.");
  
          return showProfile(form, form2, continueUrl);
      }
  
      @Authenticated(value = {LoggedIn.class, HasRole.class})
      @Transactional
      public Result postServiceProfile(String continueUrl) {
          Form<UserProfileForm> form = Form.form(UserProfileForm.class).bindFromRequest();
  
          if (form.hasErrors()) {
              Form<UserProfilePictureForm> form2 = Form.form(UserProfilePictureForm.class);
              Logger.error(form.errors().toString());
              return showProfile(form, form2, continueUrl);
          } else {
              UserProfileForm userProfileForm = form.get();
  
              if (!"".equals(userProfileForm.password)) {
                  if (!userProfileForm.password.equals(userProfileForm.confirmPassword)) {
                      Form<UserProfilePictureForm> form2 = Form.form(UserProfilePictureForm.class);
                      form.reject("profile.error.passwordsDidntMatch");
                      return showProfile(form, form2, continueUrl);
                  }
                  userProfileService.updateProfile(IdentityUtils.getUserJid(), userProfileForm.name, userProfileForm.password);
              } else {
                  userProfileService.updateProfile(IdentityUtils.getUserJid(), userProfileForm.name);
              }
  
              ControllerUtils.getInstance().addActivityLog(userActivityService, "Update profile.");
              if (continueUrl == null) {
                  return redirect(routes.UserProfileController.profile());
              } else {
                  return redirect(routes.UserProfileController.serviceProfile(continueUrl));
              }
          }
      }
  
      @BodyParser.Of(value = BodyParser.MultipartFormData.class, maxLength = (2 << 20))
      @Authenticated(value = {LoggedIn.class, HasRole.class})
      @Transactional
      public Result postServiceAvatar(String continueUrl) {
          if (request().body().isMaxSizeExceeded()) {
              Form<UserProfileForm> form = Form.form(UserProfileForm.class);
              Form<UserProfilePictureForm> form2 = Form.form(UserProfilePictureForm.class);
              form2.reject("profile.error.overSizeLimit");
              return showProfile(form, form2, continueUrl);
          } else {
              Http.MultipartFormData body = request().body().asMultipartFormData();
              Http.MultipartFormData.FilePart avatar = body.getFile("avatar");
  
              if (avatar != null) {
                  String contentType = avatar.getContentType();
                  if (!((contentType.equals("image/png")) || (contentType.equals("image/jpg")) || (contentType.equals("image/jpeg")))) {
                      Form<UserProfileForm> form = Form.form(UserProfileForm.class);
                      Form<UserProfilePictureForm> form2 = Form.form(UserProfilePictureForm.class);
                      form2.reject("error.profile.not_picture");
                      return showProfile(form, form2, continueUrl);
                  } else {
                      try {
                          String profilePictureName = userProfileService.updateProfilePicture(IdentityUtils.getUserJid(), avatar.getFile(), FilenameUtils.getExtension(avatar.getFilename()));
                          String profilePictureUrl = userProfileService.getAvatarImageUrlString(profilePictureName);
                          try {
                              new URL(profilePictureUrl);
                              session("avatar", profilePictureUrl.toString());
                          } catch (MalformedURLException e) {
                              session("avatar", org.iatoki.judgels.jophiel.controllers.apis.routes.UserAPIController.renderAvatarImage(profilePictureName).absoluteURL(request()));
                          }
  
                          ControllerUtils.getInstance().addActivityLog(userActivityService, "Update avatar.");
  
                          if (continueUrl == null) {
                              return redirect(org.iatoki.judgels.jophiel.controllers.routes.UserProfileController.profile());
                          } else {
                              return redirect(routes.UserProfileController.serviceProfile(continueUrl));
                          }
                      } catch (IOException e) {
                          Form<UserProfileForm> form = Form.form(UserProfileForm.class);
                          Form<UserProfilePictureForm> form2 = Form.form(UserProfilePictureForm.class);
                          form2.reject("profile.error.cantUpload");
                          return showProfile(form, form2, continueUrl);
                      }
                  }
              } else {
                  Form<UserProfileForm> form = Form.form(UserProfileForm.class);
                  Form<UserProfilePictureForm> form2 = Form.form(UserProfilePictureForm.class);
                  form2.reject("profile.error.not_picture");
                  return showProfile(form, form2, continueUrl);
              }
          }
      }
  
      private Result showProfile(Form<UserProfileForm> form, Form<UserProfilePictureForm> form2, String continueUrl) {
          LazyHtml content;
          if (continueUrl == null) {
  