Exemplo n.º 1
0
        private ResetPasswordResponse GetResetPasswordDetail(ResetPasswordTokenRequest resetPasswordTokenRequest)
        {
            var response = new ResetPasswordResponse();
            try
            {
                response = DataContext.ResetPasswords.First(x => x.Token == resetPasswordTokenRequest.Token).MapTo<ResetPasswordResponse>();

                if (response.ExpireDate < DateTime.Now)
                {
                    response.IsSuccess = false;
                    response.Message = "Token Already Expired!";
                    return response;
                }
                if (response.Status)
                {
                    response.IsSuccess = false;
                    response.Message = "Token Already Used!";
                    return response;
                }

                response.Profile = GetUserByEmail(new GetUserRequest { Email = response.Email }).MapTo<ResetPasswordResponse.User>();
                response.IsSuccess = true;
            }
            catch (System.InvalidOperationException x)
            {
                return new ResetPasswordResponse
                {
                    IsSuccess = false,
                    Message = x.Message
                };
            }
            return response;
        }
Exemplo n.º 2
0
 public ResetPasswordResponse ResetPassword(ResetPasswordRequest request)
 {
     var response = new ResetPasswordResponse();
     response = this.GenerateToken(request);
     return response;
 }
Exemplo n.º 3
0
        private ResetPasswordResponse GenerateToken(ResetPasswordRequest request)
        {
            var response = new ResetPasswordResponse();

            ///Try to save token to database
            try
            {
                response.Salt = crypto.Salt != null ? crypto.Salt : crypto.GenerateSalt(crypto.HashIterations, crypto.SaltSize);

                response.Email = request.Email;
                response.ExpireDate = DateTime.Now.AddDays(3);
                response.Token = crypto.Compute(request.Email, response.Salt);
                //var entity = new ResetPassword { Email = response.Email, Token = response.Token, Salt = response.Salt, ExpireDate = response.ExpireDate };
                var entity = response.MapTo<ResetPassword>();
                DataContext.ResetPasswords.Add(entity);
                DataContext.SaveChanges();
                response.IsSuccess = true;
                response.Message = "Password Token Successfully Created";
            }
            catch (System.InvalidOperationException x)
            {
                return new ResetPasswordResponse
                {
                    IsSuccess = false,
                    Message = x.Message
                };
            }
            return response;
        }
Exemplo n.º 4
0
 public ResetPasswordResponse GetUserByToken(ResetPasswordTokenRequest request)
 {
     var response = new ResetPasswordResponse();
     response = this.GetResetPasswordDetail(new ResetPasswordTokenRequest { Token = request.Token });
     return response;
 }