예제 #1
0
        public async Task <ActionResult> Edit(ProfileEditModel model)
        {
            if (ModelState.IsValid)
            {
                user.City       = model.City;
                user.FirstName  = model.FirstName;
                user.LastName   = model.LastName;
                user.Email      = model.Email;
                user.Address    = model.Address;
                user.PostalCode = model.PostalCode;
                user.City       = model.City;

                if (model.ImagePath != null && model.ImagePath.ContentLength > 0)
                {
                    string serverPath = "~/Assets/UserImages";

                    string path = Path.Combine(Server.MapPath(serverPath), user.Id + Path.GetFileName(model.ImagePath.FileName));
                    model.ImagePath.SaveAs(path);
                    user.ImagePath = serverPath + "/" + user.Id + Path.GetFileName(model.ImagePath.FileName);
                }

                await UserManager.UpdateAsync(user);

                return(RedirectToAction("Index"));
            }
            return(View(user));
        }
예제 #2
0
        public async Task <IActionResult> Profile(ProfileEditModel model)
        {
            var user = await _userManager.FindByNameAsync(User.Identity.Name);

            if (user == null)
            {
                return(RedirectToAction("Logout", "Account"));
            }
            if (ModelState.IsValid)
            {
                user.UserName = model.UserName;
                user.Email    = model.Email;
                var result = await _userManager.UpdateAsync(user);

                if (result.Succeeded)
                {
                    Claim claim        = ((ClaimsIdentity)User.Identity).FindFirst("IsPersistent");
                    bool  IsPersistent = claim != null?Convert.ToBoolean(claim.Value) : false;

                    await _signInManager.SignOutAsync();

                    await _signInManager.SignInAsync(user, IsPersistent);

                    return(RedirectToAction("Profile", "Account"));
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError(string.Empty, error.Description);
                    }
                }
            }
            return(View(model));
        }
예제 #3
0
        protected virtual void FillEditData(ProfileEditModel model)
        {
            var mediaSettings = GetMediaSettings();

            ViewData["AllowedMediaExtensions"] = mediaSettings.AllowedMediaExtensions;
            model.MediaRootId = mediaSettings.MediaRootId;
        }
예제 #4
0
        public virtual ActionResult Edit(ProfileEditModel model)
        {
            var member = MapToMemberDTO(model);

            _intranetMemberService.Update(member);

            return(RedirectToCurrentUmbracoPage());
        }
예제 #5
0
        protected virtual void FillEditData(ProfileEditModel model)
        {
            var mediaSettings = GetMediaSettings();

            ViewData["AllowedMediaExtensions"] = mediaSettings.AllowedMediaExtensions;
            model.MediaRootId = mediaSettings.MediaRootId;
            model.ProfileUrl  = _profileLinkProvider.GetProfileLink(model.Id);
        }
예제 #6
0
        public virtual ActionResult Edit(ProfileEditModel model)
        {
            var user = MapToUserDTO(model);

            _intranetUserService.Save(user);

            return(RedirectToCurrentUmbracoPage());
        }
예제 #7
0
        public async Task <IActionResult> EditProfile()
        {
            var member = await HttpContext.GetMemberAsync();

            var model = new ProfileEditModel();
            await _appService.PrepareModelAsync(model, member);

            return(View(model));
        }
예제 #8
0
        protected virtual UpdateMemberDto MapToMemberDTO(ProfileEditModel model)
        {
            var newMedias = _mediaHelper.CreateMedia(model).ToList();

            var updateMember = model.Map <UpdateMemberDto>();

            updateMember.NewMedia = newMedias.Count > 0 ? newMedias.First() : default(int?);

            return(updateMember);
        }
예제 #9
0
        /// <summary>
        ///     Task which changes the user's password.
        /// </summary>
        /// <param name="model">Model to derive the password from.</param>
        /// <returns>True if the operation was successful. False otherwise.</returns>
        private async Task <bool> ChangePassword(ProfileEditModel model)
        {
            var user = await _userManager.FindByNameAsync(model.Email);

            var code = await _userManager.GeneratePasswordResetTokenAsync(user);

            var result = await _userManager.ResetPasswordAsync(user, code, model.Password);

            return(result.Succeeded);
        }
        public RedirectToRouteResult Save(ProfileEditModel form)
        {
            var profile = _profileRepository.Find(form.Username);

            profile.Email = form.Email;
            profile.FirstName = form.FirstName;
            profile.LastName = form.LastName;

            return RedirectToAction("Index");
        }
예제 #11
0
        protected virtual IntranetUserDTO MapToUserDTO(ProfileEditModel model)
        {
            var newMedias = _mediaHelper.CreateMedia(model).ToList();

            var updateUser = model.Map <IntranetUserDTO>();

            updateUser.NewMedia = newMedias.Count > 0 ? newMedias.First() : default(int?);

            return(updateUser);
        }
예제 #12
0
        public IActionResult EditProfile(ProfileEditModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var usr     = _userManager.GetUserAsync(HttpContext.User).Result;
            var profile = Context.Users.First(u => u.Id == usr.Id);

            if (model.FirstName != null)
            {
                profile.FirstName = model.FirstName;
            }
            if (model.LastName != null)
            {
                profile.LastName = model.LastName;
            }
            if (model.PhoneNumber != null)
            {
                if (Regex.Matches(model.PhoneNumber, @"(\+359|359|0)\d{9}").Count > 0)
                {
                    profile.PhoneNumber = model.PhoneNumber;
                }
                else
                {
                    ModelState.AddModelError("PhoneNumber", "Invalid phone number format.");
                    return(View(model));
                }
            }

            if (model.Password != null)
            {
                var isChangedSuccessfully = ChangePassword(model).Result;

                if (!isChangedSuccessfully)
                {
                    ModelState
                    .AddModelError("Password", "Failed to update password. Please try again later");
                }
            }

            if (profile.FirstName != model.FirstName ||
                profile.LastName != model.LastName ||
                profile.PhoneNumber != model.PhoneNumber)
            {
                Context.Users.Update(profile);

                Context.SaveChanges();
            }

            TempData["success"] = "Profile updated successfully! ";

            return(View());
        }
예제 #13
0
        public IActionResult Settings()
        {
            var _user = HttpContext.Session.GetSession <User>("User");

            var model = new ProfileEditModel();

            model.UserInfo = _userManager.GetUserInfo(_user.Username, _user.ID);
            model.User     = _userManager.getOne(a => a.ID == _user.ID);

            return(View(model));
        }
예제 #14
0
        public async Task <IHttpActionResult> Edit([FromBody] ProfileEditModel editModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            await _profileService.Edit(editModel);

            var result = _profileLinkProvider.GetProfileLink(editModel.Id);

            return(Ok(result));
        }
예제 #15
0
        public ActionResult EditProfile()
        {
            var user  = UnitOfWork.Users.GetUser(User.Identity.Name);
            var model = new ProfileEditModel
            {
                FirstName = user.FirstName,
                LastName  = user.LastName,
                Email     = user.Email,
                Age       = user.Age
            };

            return(PartialView(model));
        }
예제 #16
0
        public ActionResult EditProfile(ProfileEditModel model)
        {
            if (ModelState.IsValid)
            {
                var user = UnitOfWork.Users.GetUser(User.Identity.Name);
                ModelMapper.Map(model, user);
                UnitOfWork.Users.SaveUser(user);
                UnitOfWork.SaveChanges();
                return(RedirectToAction("UserInfo"));
            }

            return(View(model));
        }
예제 #17
0
        /* public IEnumerable<PermissionType> GetPermissions(IEnumerable<string> roles) =>
         *   context.Roles
         *       .Where(r => roles.Contains(r.Name))
         *       .SelectMany(r => r.Permissions.Select(p => p.Permission.Type))
         *       .Distinct()
         *       .ToList();*/

        public async Task <ApplicationUser> Update(string id, ProfileEditModel model)
        {
            ApplicationUser user = this.context.Users.Find(id);

            user.FirstName = model.FirstName;
            user.LastName  = model.LastName;
            user.Birthday  = model.Birthday;

            this.context.Users.Update(user);
            await this.context.SaveChangesAsync();

            return(user);
        }
예제 #18
0
        public async Task Edit(ProfileEditModel editModel)
        {
            var newMedias = _mediaHelper.CreateMedia(editModel, MediaFolderTypeEnum.MembersContent).ToArray();

            var member = editModel.Map <UpdateMemberDto>();

            member.NewMedia = newMedias.Length > 0
                ? newMedias.First()
                : default(int?);

            await _userTagService.ReplaceAsync(editModel.Id, editModel.TagIdsData);

            await _intranetMemberService.UpdateAsync(member);
        }
예제 #19
0
        public async Task <IActionResult> Profile()
        {
            var user = await _userManager.FindByNameAsync(User.Identity.Name);

            ProfileEditModel model = new ProfileEditModel {
                UserName = user.UserName, Email = user.Email
            };

            if (user != null)
            {
                return(View(model));
            }
            return(RedirectToAction("Logout", "Account"));
        }
예제 #20
0
        public IActionResult EditProfile()
        {
            var usr = _userManager.GetUserAsync(HttpContext.User).Result;

            var profile = new ProfileEditModel
            {
                Email       = usr.Email,
                FirstName   = usr.FirstName,
                LastName    = usr.LastName,
                PhoneNumber = usr.PhoneNumber
            };

            return(View(profile));
        }
예제 #21
0
        public ActionResult EditProfile(string UserId)
        {
            try
            {
                ProfileEditModel model = new ProfileEditModel();
                model.userDetails = new sw.UserDetails();

                // model.ncsUserDetails = new sw.NCSUserDetails();
                Guid guidUserId;
                if (string.IsNullOrEmpty(UserId))
                {
                    user       = Membership.GetUser(User.Identity.Name, false);
                    guidUserId = (Guid)user.ProviderUserKey;
                }
                else
                {
                    if (!System.Web.Security.Roles.IsUserInRole("ADMINISTRATOR") && !System.Web.Security.Roles.IsUserInRole("Organisation Admin"))
                    {
                        throw new Exception("You Do not have the privilege to perform this action");
                    }
                    guidUserId = Guid.Parse(UserId);
                    user       = Membership.GetUser(guidUserId, false);
                }

                var userDetails = (from x in swdb.UserDetails where x.UserId == guidUserId select x).ToList();
                if (userDetails.Count > 0)
                {
                    model.userDetails = userDetails.FirstOrDefault();
                }
                else
                {
                    model.userDetails.UserId = guidUserId;
                }

                GetOrganisation obj          = new GetOrganisation();
                sw.Organisation organisation = new sw.Organisation();
                organisation = obj.byUser(user);

                model.organisation = organisation;
                // model.BranchList = new SelectList(db.OfficeBranch.OrderBy(x => x.BranchName), "ID", "BranchName");
                return(View(model));
            }
            catch (Exception ex)
            {
                //ToDo: Log with Elmah
                TempData["message"] = Settings.Default.GenericExceptionMessage;
                return(RedirectToAction("Index", "Home", new { area = "Admin" }));
            }
        }
예제 #22
0
        public Task PrepareProfileAsync(User user, ProfileEditModel model)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            user = _mapper.Map(model, user);

            return(Task.CompletedTask);
        }
예제 #23
0
        public async Task <ActionResult> Edit(ProfileEditModel model, string id)
        {
            // this.ValidateUser(model, id);
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState.Errors()));
            }

            ApplicationUser user = await this.profileService.Update(id, model);

            await this.ClearUserRoles(user);

            // await this.userManager.AddToRolesAsync(user, model.Roles);
            return(this.Ok());
        }
예제 #24
0
        public ActionResult Create()
        {
            if (RepositoryFactory.UserRepository.Queryable.Any(x => x.Identifier == CurrentUser.Identity.Name))
            {
                Message = "You already have a profile"; //TODO: redirect to existing profile
                return(RedirectToAction("Edit"));
            }

            var model = new ProfileEditModel
            {
                Profile = new Profile(),
                Roles   = RepositoryFactory.RoleRepository.Queryable.OrderByDescending(x => x.Name).ToList()
            };

            return(View(model));
        }
예제 #25
0
        public ActionResult Edit(ProfileEditModel modelProfile)
        {
            var validImageTypes = new[]
            {
                "image/gif",
                "image/jpeg",
                "image/pjpeg",
                "image/png"
            };

            if (modelProfile.FilePicture != null && modelProfile.FilePicture.ContentLength > 0)
            {
                if (!validImageTypes.Contains(modelProfile.FilePicture.ContentType))
                {
                    ModelState.AddModelError("FilePicture", "Por favor seleccione entre una imagen GIF, JPG o PNG");
                }
            }
            if (ModelState.IsValid)
            {
                try
                {
                    if (modelProfile.FilePicture != null)
                    {
                        WebImage img = new WebImage(modelProfile.FilePicture.InputStream);
                        if (img.Width > 200 || img.Height > 200)
                        {
                            img.Resize(200, 200);
                        }

                        modelProfile.Photo = img.GetBytes();
                    }
                    var profile = _profileRepository.GetById(modelProfile.Id);
                    Mapper.Map(modelProfile, profile);
                    _profileRepository.Update(profile);
                    const string title   = "Perfil Actualizado";
                    var          content = "El perfil de" + profile.FullName + " ha sido actualizado exitosamente.";
                    _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.SuccessMessage);
                }
                catch (Exception e)
                {
                    const string title   = "Error";
                    var          content = "El perfil no se actualizó.";
                    _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.ErrorMessage);
                }
            }
            return(RedirectToAction("Index"));
        }
예제 #26
0
        public ResponseBaseModel Save([FromBody] ProfileEditModel model)
        {
            var result = _profileEditModelValidator.Validate(model);

            var profileBeforUpdation = _userProfileService.GetProfileEditModel(_sessionContext.UserSession.UserId);

            model.DefaultRole = profileBeforUpdation.DefaultRole;

            if (!result.IsValid)
            {
                var firstOrDefault = result.Errors.FirstOrDefault();
                if (firstOrDefault != null)
                {
                    return new ResponseBaseModel {
                               IsSuccess = false, Message = firstOrDefault.ErrorMessage
                    }
                }
                ;
            }
            try
            {
                if (string.IsNullOrEmpty(model.Password))
                {
                    model.Password = null;

                    model.ConfirmPassword = null;
                }

                model.DateCreated = DateTime.Now;

                _userProfileService.SaveProfile(model);
            }
            catch (Exception exception)
            {
                _logger.Error(string.Format("Message {0}\n " +
                                            "Stack Trace {1}", exception.Message, exception.StackTrace));
                return(new ResponseBaseModel {
                    IsSuccess = false, Message = exception.Message
                });
            }

            return(new ResponseBaseModel {
                IsSuccess = true, Message = "success"
            });;
        }
    }
예제 #27
0
        public ActionResult EditProfile(ProfileEditModel row)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    sw.UserDetails userDetails = new sw.UserDetails();
                    userDetails              = row.userDetails;
                    userDetails.ModifiedBy   = User.Identity.Name;
                    userDetails.ModifiedDate = DateTime.Now;

                    var record = (from x in swdb.UserDetails where x.UserId == userDetails.UserId select x).FirstOrDefault();

                    if (record != null)
                    {
                        record.FirstName   = userDetails.FirstName;
                        record.LastName    = userDetails.LastName;
                        record.MiddleName  = userDetails.MiddleName;
                        record.PhoneNumber = userDetails.PhoneNumber;

                        swdb.SaveChanges();
                    }
                    else
                    {
                        swdb.UserDetails.Add(userDetails);
                        swdb.SaveChanges();
                    }



                    TempData["message"] = "Account details was saved successfully";
                    return(RedirectToAction("EditProfile", new { UserId = row.userDetails.UserId }));
                }
                else
                {
                    return(RedirectToAction("EditProfile", new { UserId = row.userDetails.UserId }));
                }
            }
            catch (Exception ex)
            {
                //ToDo: Log with Elmah
                Elmah.ErrorSignal.FromCurrentContext().Raise(ex);
                TempData["message"] = Settings.Default.GenericExceptionMessage;
                return(RedirectToAction("Index", "Home", new { area = "Admin" }));
            }
        }
예제 #28
0
        /// <summary>
        /// Edit your profile
        /// </summary>
        /// <returns></returns>
        public ActionResult Edit()
        {
            var profile =
                RepositoryFactory.ProfileRepository.Queryable.SingleOrDefault(
                    x => x.User.Identifier == CurrentUser.Identity.Name);

            if (profile == null)
            {
                Message = "You don't yet have a profile, please create one now";
                return(RedirectToAction("Create"));
            }

            var model = new ProfileEditModel
            {
                Profile = profile,
                Roles   = RepositoryFactory.RoleRepository.Queryable.OrderByDescending(x => x.Name).ToList()
            };

            return(View(model));
        }
예제 #29
0
        private async Task SaveProfileImageAsync(User user, ProfileEditModel model)
        {
            var fileClient     = HttpContext.RequestServices.GetRequiredService <IFileClient>();
            var imageProcessor = HttpContext.RequestServices.GetRequiredService <IImageProcessor>();

            await _appService.PrepareMediaAsync(new[] { user.UserImage }, new[] { model.UserImage },
                                                createMedia : async(image) =>
            {
                image.DirectoryName = user.Id.ToString();

                var source = await fileClient.GetAsync(image.DirectoryName, image.FileName);

                if (source != null)
                {
                    var(imageWidth, imageHeight) = await imageProcessor.GetImageSizeAsync(source);

                    image.Width    = imageWidth;
                    image.Height   = imageHeight;
                    image.FileSize = source.Length;

                    await _mediaService.CreateAsync(image);

                    user.UserImageId = image.Id;
                    await _userService.UpdateAsync(user);
                }
            },
                                                updateMedia : async(media) =>
            {
                await _mediaService.UpdateAsync(media);
            },
                                                deleteMedia : async(media) =>
            {
                user.UserImageId = null;
                user.UserImage   = null;

                await _userService.UpdateAsync(user);
                await _mediaService.DeleteAsync(media);
            });
        }
예제 #30
0
        public void SaveProfile(ProfileEditModel profileEditModel)
        {
            var user = Mapper.Map <ProfileEditModel, User>(profileEditModel);

            user.UserLogin.IsSecurityQuestionVerified = true;
            user.UserLogin.UserVerified = true;
            if (profileEditModel.Id > 0 && string.IsNullOrEmpty(profileEditModel.Password))
            {
                var existingUser = _userRepository.GetUser(profileEditModel.Id);
                user.UserLogin.Password = existingUser.UserLogin.Password;
                user.UserLogin.Salt     = existingUser.UserLogin.Salt;
            }
            else if (!string.IsNullOrEmpty(profileEditModel.Password))
            {
                var secureHash = _oneWayHashingService.CreateHash(profileEditModel.Password);
                user.UserLogin.Password = secureHash.HashedText;
                user.UserLogin.Salt     = secureHash.Salt;
            }

            _addressService.SaveAfterSanitizing(user.Address);

            _userRepository.SaveUser(user);
        }
예제 #31
0
        public async Task <IActionResult> EditProfile(ProfileEditModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var member = await HttpContext.GetMemberAsync();

                await _appService.PrepareProfileAsync(member, model);

                var result = await _userService.UpdateAsync(member);

                if (result.Succeeded)
                {
                    await SaveProfileImageAsync(member, model);

                    TempData.AddAlert(AlertMode.Notify, AlertType.Success, $"Profile was updated.");
                }
                else
                {
                    ModelState.AddIdentityResult(result);
                }
            }

            return(RedirectToAction(nameof(EditProfile), new { returnUrl }));
        }