Exemplo n.º 1
0
        /// <summary>
        /// Change the password of a user when the user uses the "remember password option"
        /// </summary>
        /// <param name="order">The info of the reset password</param>
        /// See <see cref="Areas.Identity.Models.ResetPassword"/> to know the param structure
        /// <returns></returns>
        public IActionResult reset([FromBody] ResetPassword order)
        {
            User user = new User();

            if (!ValidTokenPassword.isValid(order.tokenPassword, ref user, _context))
            {
                return(BadRequest());
            }
            if (!PasswordHasher.validPassword(order.password))
            {
                return(BadRequest());
            }

            try
            {
                user.password           = PasswordHasher.hashPassword(order.password);
                user.tokenPassword      = null;
                user.tokenP_expiresTime = DateTime.Now;
                _context.Update(user);
                _context.SaveChanges();

                return(Ok(new { success = "PassChanged" }));
            }
            catch (Exception)
            {
                return(StatusCode(500));
            }
        }
        /// <summary>
        /// Validate the password token to know if the user
        /// can change the password
        /// </summary>
        /// <param name="passwordToken">The password token</param>
        /// <returns>Status Code 200 if the password is valid, 400 otherwise</returns>
        public IActionResult checkPassword([Required] string passwordToken)
        {
            User u = new User();

            if (!ValidTokenPassword.isValid(passwordToken, ref u, _context))
            {
                return(BadRequest());
            }

            return(Ok());
        }