Exemplo n.º 1
0
        public async Task <IActionResult> passwordresetconfirm([FromBody] password_reset_token userobj)
        {
            try
            {
                var          obj         = new returnMsg();
                IdentityUser user        = _context.Users.Where(r => r.Email == userobj.email).First();
                var          parsedtoken = userobj.token.Replace(" ", "+");
                var          result      = await _userManager.ResetPasswordAsync(user, parsedtoken, userobj.new_password);

                if (result.Succeeded)
                {
                    obj.message = "Your Password has been successfully changed.";
                    return(StatusCode(StatusCodes.Status200OK, JsonConvert.SerializeObject(obj)));
                }
                else
                {
                    var exceptionText = result.Errors.First();
                    return(StatusCode(StatusCodes.Status500InternalServerError, exceptionText.Description));
                }
            }
            catch
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "No account found with that email address."));
            }
        }
Exemplo n.º 2
0
        public async Task <JsonResult> changeprofiledata([FromBody] UserProfile userobj)
        {
            try
            {
                var         obj  = new returnMsg();
                UserProfile user = _context.UserProfile.Where(r => r.Id == userobj.Id).First();
                if (user != null)
                {
                    user.FirstName   = userobj.FirstName;
                    user.LastName    = userobj.LastName;
                    user.PhoneNumber = userobj.PhoneNumber;
                    _context.Update(user);
                    await _context.SaveChangesAsync();

                    obj.message = "Profile Information Updated.";
                }
                else
                {
                    obj.message = "User Not Found.";
                }
                return(new JsonResult(obj));
            }
            catch (Exception e)
            {
                return(new JsonResult(e.Message));
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> changepassword([FromBody] newpass userobj)
        {
            var          obj    = new returnMsg();
            IdentityUser user   = _context.Users.Where(r => r.Email == userobj.email).First();
            var          result = await _userManager.ChangePasswordAsync(user, userobj.current_password, userobj.new_password);

            if (result.Succeeded)
            {
                obj.message = "Your Password has been successfully changed.";
            }
            else
            {
                var exceptionText = result.Errors.First();
                return(StatusCode(StatusCodes.Status500InternalServerError, exceptionText.Description));
            }
            return(Content(JsonConvert.SerializeObject(obj)));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> accountrecovery(string email)
        {
            try
            {
                var          obj  = new returnMsg();
                IdentityUser user = _context.Users.Where(r => r.Email == email).First();
                var          code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                obj.message = "Password Reset Link sent to " + email;
                _AuthMessageSender.SendEmailAsync(_appData.ApplicationName + " Password Reset Email", "Please reset your account by clicking this link: "
                                                  + _appData.PasswordResetLink + "?email=" + email + "&token=" + code, _AuthMessageSender.SystemGeneralEmail, new List <string> {
                    email
                });
                //+_appData.PasswordResetLink + "?email=" + email + "&token=" + code, _AuthMessageSender.SystemGeneralEmail, new List<string> { email });

                return(StatusCode(StatusCodes.Status200OK, JsonConvert.SerializeObject(obj)));
            }
            catch
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, "No account found with that email address."));
            }
        }