Esempio n. 1
0
        public async Task <IActionResult> ChangePassword(AjaxUserChangrPassword model, CancellationToken cancellationToken)
        {
            CustomUser user = await _userManager.FindByIdAsync(model.Id);

            AjaxResult result = new AjaxResult("Error");

            if (user != null)
            {
                IdentityResult changeResult = await _userManager.ChangePasswordAsync(user, model.OldPassWord, model.NewPassWords);

                if (changeResult.Succeeded)
                {
                    result.Status = "Success";
                    result.MessageWhenSuccessed = "پسوورد با موفقیت تغییر کرد";
                    result.RedirectUrl          = "/User/Home/Index";
                    return(new JsonResult(result));
                }
                else
                {
                    ModelState.AddModelStateError(changeResult.Errors.Select(c => c.Description));
                }
                result.AddErrors(ModelState);
                return(new JsonResult(result));
            }
            ModelState.AddModelError("", "کاربر یافت نشد");
            result.AddErrors(ModelState);
            return(new JsonResult(result));
        }
Esempio n. 2
0
        public async Task <IActionResult> EditProfileImage(AjaxUserEditProfileImage model, CancellationToken cancellationToken)
        {
            AjaxResult result = new AjaxResult("Error");

            CustomUser user = await _userManager.FindByIdAsync(model.Id);

            if (user != null)
            {
                string uploads             = Path.Combine(_hostingEnvironment.WebRootPath, "images", "UserProfile");
                string OldProfileImagePath = $"{_hostingEnvironment.WebRootPath}\\images\\UserProfile\\{user.Avatar}";
                string strFilePath         = await fileHandler.UploadFileAsync(model.FormFile, uploads, cancellationToken, OldProfileImagePath);

                user.Avatar = strFilePath;
                IdentityResult Result = await _userManager.UpdateAsync(user);

                if (Result.Succeeded)
                {
                    result.Status               = "Success";
                    result.RedirectUrl          = "/User/Home/Index";
                    result.MessageWhenSuccessed = "تصویر پروفایل با موفقیت عوض شد";
                    return(new JsonResult(result));
                }
                else
                {
                    ModelState.AddModelStateError(Result.Errors.Select(c => c.Description));
                }
            }
            ModelState.AddModelError("", "کاربر یافت نشد");
            result.AddErrors(ModelState);
            return(new JsonResult(result));
        }
Esempio n. 3
0
        public async Task <IActionResult> EditProfile(UserProfileViewModel model)
        {
            CustomUser user = await _userManager.GetUserAsync(User);

            user.ShowUserName   = model.UserName;
            user.PhoneNumber    = model.PhoneNumber;
            user.EmailConfirmed = user.Email == model.Email;
            user.Email          = model.Email;
            IdentityResult result = await _userManager.UpdateAsync(user);

            if (result.Succeeded)
            {
                return(Redirect(nameof(Index)));
            }
            else
            {
                ModelState.AddModelStateError(result.Errors.Select(c => c.Description));
            }
            return(View(model));
        }