public JsonResult ForgotPassword(string email)
        {
            var result = new JsonResult {
                ContentType = "text"
            };
            var userModel = this.AccountService.CheckUsernameExists(email, email);
            var baseUrl   = Request.Url.Scheme + "://" + Request.Url.Authority + Request.ApplicationPath.TrimEnd('/') + "/";

            if (userModel != null)
            {
                if (string.IsNullOrEmpty(userModel.Password))
                {
                    result.Data = new { type = "error", msg = Constant.CONST_MESSAGE_USERNAME_LOGIN_WITH_GG_FB }
                }
                ;
                else
                {
                    var salt = EncryptionUtility.BcryptGenerateSalt(12);

                    var token = EncryptionUtility.Base64Encode(userModel.ID + " " + salt);

                    if (EmailSender.SendMailResetPassword(userModel.Email, baseUrl, token))
                    {
                        result.Data = new { type = "success", msg = Constant.CONST_MESSAGE_EMAIL_SENT_RESET_PASSWORD_SUCCESS };
                        userModel.ResetPasswordToken = salt;
                        userModel.ExpireToken        = DateTime.Now.AddMinutes(30);

                        this.AccountService.Update(userModel);
                    }
                }
            }
            else
            {
                result.Data = new { type = "error", msg = Constant.CONST_MESSAGE_USERNAME_OR_EMAIL_INVALID }
            };

            return(result);
        }
Beispiel #2
0
        public void GetBase64EncodedValueTest()
        {
            var result = EncryptionUtility.Base64Encode("photo search");

            Assert.AreEqual(result, "cGhvdG8gc2VhcmNo");
        }