Beispiel #1
0
        public ActionResult Save(EditProfileViewModel model)
        {
            TryValidateModel(model);
            if (!ModelState.IsValid)
                return Preview(SecurityManager.AuthenticatedUser.Id);

            User currentUser = Session.Get<User>(SecurityManager.AuthenticatedUser.Id);
            if (!String.IsNullOrEmpty(model.NewPassword))
            {
                if (model.OldPassword == currentUser.Password)
                    currentUser.Password = model.NewPassword;
                else
                {
                    ModelState.AddModelError("invPass", "Invalid password");
                    model.OldPassword = string.Empty;
                    model.NewPassword = string.Empty;
                    model.RepeatPassword = string.Empty;
                    return Preview(SecurityManager.AuthenticatedUser.Id);
                }
            }

            currentUser.Email = model.Email;
            if (model.NewAvatar != null)
            {
                Avatar newAvatar = currentUser.Avatar;
                MemoryStream target = new MemoryStream();
                model.NewAvatar.InputStream.CopyTo(target);
                byte[] data = target.ToArray();
                //Session.Delete(newAvatar);
                newAvatar = new Avatar(Guid.NewGuid(), data, currentUser, DateTime.Now, model.NewAvatar.ContentType);
                currentUser.Avatar = newAvatar;
                Session.Save(newAvatar);

            }
            MyPhoto.Web.Library.Installers.Search.AddOrUpdate(currentUser);
            SecurityManager.Logout();
            SecurityManager.AuthenticateUser(currentUser.Username, currentUser.Password);

            return RedirectToAction("/Index");
        }
Beispiel #2
0
 public ActionResult Edit()
 {
     var model = new EditProfileViewModel();
     model.Email = SecurityManager.AuthenticatedUser.Email;
     return View(model);
 }