Example #1
0
        public ApiResponse RecoverPassword(User info)
        {
            try
            {
                var validator = new UserRecoverPasswordValidator();
                var result    = validator.Validate(info);

                if (result.IsValid)
                {
                    if (dacMgr.Select(info.Email) != null)
                    {
                        info.UpdatedDate  = DateTime.Now;
                        info.TempPassword = StringCipher.Encrypt(LogicHelper.ConstructPassword(), passPhrase);
                        info.Status       = NUserStatus.ChangePassword.GetStrValue();

                        if (dacMgr.UpdateStatus(info))
                        {
                            logMgr.Info(info.Email + " success to request password change");

                            var emailMgr = new EmailMgr();

                            info.TempPassword = StringCipher.Decrypt(info.TempPassword, passPhrase);
                            if (emailMgr.SendPwdRecoveryEmail(info))
                            {
                                response.Success = true;
                            }
                            else
                            {
                                logMgr.Error(info.Email + " failed to send an email for password recovery");
                            }
                        }
                    }
                    else
                    {
                        response.ErrorList.Add(new Error {
                            Message = "Email doesn't exist in database"
                        });
                    }
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        response.ErrorList.Add(new Error {
                            Message = error.PropertyName + error.ErrorMessage
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.ErrorList.Add(new Error {
                    Message = "Internal Server Error Code:500"
                });
                logMgr.Error(ex);
            }

            return(response);
        }
Example #2
0
        public ApiResponse Add(User info)
        {
            try
            {
                var validator = new UserRegistrtionValidator();
                var result    = validator.Validate(info);

                if (result.IsValid)
                {
                    info.Password = StringCipher.Encrypt(info.Password, passPhrase);
                    info.Status   = NUserStatus.Active.GetStrValue();
                    info.Token    = Guid.NewGuid().ToString();

                    if (dacMgr.Insert(info))
                    {
                        logMgr.Info("Register new an user " + info.Email);


                        var emailMgr = new EmailMgr();

                        if (emailMgr.SendRegConfirmEmail(info))
                        {
                            response.Success = true;
                        }
                        else
                        {
                            logMgr.Error(info.Email + " failed to send a registration email");
                        }
                    }
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        response.ErrorList.Add(new Error {
                            Message = error.PropertyName + error.ErrorMessage
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.ErrorList.Add(new Error {
                    Message = "Internal Server Error Code:500"
                });

                logMgr.Error(ex);
            }

            return(response);
        }
Example #3
0
        public ApiResponse Add(User info)
        {
            try
            {
                var validator = new UserRegistrtionValidator();
                var result = validator.Validate(info);

                if (result.IsValid)
                {
                    info.Password = StringCipher.Encrypt(info.Password, passPhrase);
                    info.Status = NUserStatus.Active.GetStrValue();
                    info.Token = Guid.NewGuid().ToString();

                    if (dacMgr.Insert(info))
                    {
                        logMgr.Info("Register new an user " + info.Email);


                        var emailMgr = new EmailMgr();

                        if (emailMgr.SendRegConfirmEmail(info))
                            response.Success = true;
                        else
                            logMgr.Error(info.Email + " failed to send a registration email");
                    }
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        response.ErrorList.Add(new Error { Message = error.PropertyName + error.ErrorMessage });
                    }
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.ErrorList.Add(new Error { Message = "Internal Server Error Code:500" });

                logMgr.Error(ex);
            }

            return response;
        }
Example #4
0
        public ApiResponse ChangePassword(User info)
        {
            try
            {
                var validator = new UserChangePasswordValidator();
                var result = validator.Validate(info);

                if (result.IsValid)
                {
                    if (dacMgr.Select(info.Email) != null)
                    {
                        info.UpdatedDate = DateTime.Now;
                        info.TempPassword = StringCipher.Encrypt(LogicHelper.ConstructPassword(), passPhrase);
                        info.Status = NUserStatus.ChangePassword.GetStrValue();

                        if (dacMgr.UpdateStatus(info))
                        {
                            var emailMgr = new EmailMgr();

                            info.TempPassword = StringCipher.Decrypt(info.TempPassword, passPhrase);

                            if (emailMgr.SendPwdChangeNotifyEmail(info))
                                response.Success = true;
                            else
                                logMgr.Error(info.Email + " failed to send an email for password change notification");
                        }
                    }
                    else
                    {
                        response.ErrorList.Add(new Error { Message = "Email doesn't exist in database" });
                    }
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        response.ErrorList.Add(new Error { Message = error.ErrorMessage });
                    }
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.ErrorList.Add(new Error { Message = "Internal Server Error Code:500" });
                logMgr.Error(ex);
            }

            return response;
        }