Beispiel #1
0
        public object Any(ResetViewModel request)
        {
            ValidationResult validations = new ResetAccountValidator().Validate(request);

            if (!validations.IsValid)
            {
                request.ResponseResult.ResultStatus = ResultStatuses.Error;
                foreach (var item in validations.Errors)
                {
                    request.ResponseResult.Messages.Add(item.ErrorMessage);
                }

                return(request);
            }

            string de = request.Hash.Decrypt("hash");

            var userAuth = UserAuthRepository.GetUserAuthByUserName(de);

            if (userAuth != null)
            {
                UserAuthRepository.UpdateUserAuth(userAuth, userAuth, request.Password);
            }

            request.ResponseResult.ResultStatus = ResultStatuses.Success;
            request.ResponseResult.Messages.Clear();

            return(request);
        }
Beispiel #2
0
        public object Any(ResetPassword request)
        {
            var res  = new ResetPasswordResponse();
            var user = UserAuthRepository.GetUserAuthByUserName(request.Email);

            if (null == user)
            {
                res.Success = false;
                res.Message = "Invalid email address.";
                return(res);
            }

            var secret = Cache.Get <string>($"password:secret:{user.Email}");

            if (secret.IsNullOrEmpty() || !secret.Equals(request.Token))
            {
                res.Success = false;
                res.Message = "Reset window expired.";
                return(res);
            }

            UserAuthRepository.UpdateUserAuth(user, user, request.Password);
            Cache.Remove($"password:secret:{user.Email}");

            using (var service = ResolveService <AuthenticateService>())
            {
                return(service.Authenticate(new Authenticate
                {
                    provider = AuthenticateService.CredentialsProvider,
                    UserName = user.Email,
                    Password = request.Password
                }));
            }
        }
Beispiel #3
0
        public object Any(ForgotPassword request)
        {
            var res  = new ForgotPasswordResponse();
            var user = UserAuthRepository.GetUserAuthByUserName(request.Email);

            if (null == user)
            {
                res.Success = false;
                res.Message = "Invalid email address.";
                return(res);
            }

            var secret = Regex.Replace(SessionExtensions.CreateRandomBase62Id(32), @"[^\w\d]", "",
                                       RegexOptions.IgnoreCase);
            var link    = $"{Configuration.Web.Domain}{Configuration.Web.PasswordResetLinkFormat.Fmt(user.Email, secret)}";
            var message = new MimeMessage();

            message.From.Add(new MailboxAddress(Configuration.Mail.From));
            message.To.Add(new MailboxAddress(user.Email));
            message.Subject = "[Derprecated] Password Reset";
            message.Body    = new TextPart("html")
            {
                Text =
                    $@"
                <html>
                    <head></head>
                    <body>
                        <p>
                            Click on the following link to reset your password:
                            <br/><br/>
                            <a href=""{
                        link}"">{link
                        }</a>
                            <br/><br/>
                            This link will expire in 4 hours.
                        </p>
                    </body>
                </html>
                "
            };

            Cache.Set($"password:secret:{user.Email}", secret, Expiration);
            SmtpClient.Send(message);

            res.Success = true;
            res.Message = null;

            return(res);
        }
Beispiel #4
0
        public object Any(LogonModels request)
        {
            if (request.GetInfo)
            {
                return(this.GetSession().IsAuthenticated);
            }

            if (request.LogOut)
            {
                FormsAuthentication.SignOut();
            }

            if (request.ResetPassword)
            {
                var userAuth = UserAuthRepository.GetUserAuthByUserName(request.Email);

                if (userAuth == null)
                {
                    request.ResponseResult.ResultStatus = ResultStatuses.Warning;
                    request.ResponseResult.Messages.Add("The specified Email address was not found.");
                    return(request);
                }

                EmailService.SendSmtpEmail(this.BuildEmailMessage(request.Email));

                request.ResponseResult.ResultStatus = ResultStatuses.Success;
                request.ResponseResult.Messages.Add("Please follow the link sent to your Email to reset your password.");
                return(request);
            }

            if (string.IsNullOrEmpty(request.UserName) || string.IsNullOrEmpty(request.Password))
            {
                return(false);
            }

            FormsAuthentication.SetAuthCookie(request.UserName, request.RememberMe);
            return(true);
        }