Example #1
0
        public async Task <IActionResult> PanelAsync()
        {
            var userId = this.User.FindFirst(ClaimTypes.NameIdentifier);
            var userDb = await this.userService.GetUserAsync(userId.Value);

            var model = new StudentChangePasswordViewModel
            {
                Id = userDb.Id,
            };

            return(this.View(model));
        }
Example #2
0
        public async Task <IActionResult> ChangePassword(StudentChangePasswordViewModel model)
        {
            try
            {
                if (this.ModelState.IsValid)
                {
                    var user = await this.userService.GetUserAsync(model.Id);

                    var result = await this.userManager.RemovePasswordAsync(user);

                    await this.userService.SaveChangesAsync();

                    var addResult = await this.userManager.AddPasswordAsync(user, model.Password);

                    if (addResult.Succeeded)
                    {
                        await this.signInManager.SignOutAsync();

                        this.TempData["SuccessMsg"] = "Паролата е записана успешно";
                        return(this.Redirect("/Home/Success"));
                    }
                    else
                    {
                        this.ModelState.AddModelError(string.Empty, addResult.Errors.FirstOrDefault().ToString());
                        return(this.View(model));
                    }
                }
                else
                {
                    return(this.View(model));
                }
            }
            catch (Exception exception)
            {
                var error = new ErrorViewModel
                {
                    Message   = exception.Message,
                    RequestId = this.Request.HttpContext.TraceIdentifier,
                };
                return(this.View("Error", error));
            }
        }