Пример #1
0
        public static bool resetPasswordEmail(EmailRequest requestModel, Guid uniqueId)
        {
            bool result = false;

            string page = "/account/Forgotpassword/";

            EmailData model = new EmailData();

            model.FromEmail = ("000000000000000");
            model.Subject = requestModel.Subject;
            model.Message = requestModel.Message;

            model.Message = "Hey, there!" + Environment.NewLine + "A request has been made to reset your password. Please follow this link:"
                + Environment.NewLine + _baseURL + page + uniqueId + Environment.NewLine + Environment.NewLine;
            model.Message += requestModel.Message;

            model.To = requestModel.Email;

            Send(model);

            if (model != null)
            {
                result = true;
            }

            return result;
        }
Пример #2
0
        public static bool ConfirmationEmail(EmailRequest requestModel, Guid uniqueId)
        {
            bool result = false;

            EmailData model = new EmailData();

            model.FromEmail = ("000000000000000");
            model.Subject = requestModel.Subject;
            model.Message = "Hey there!" + Environment.NewLine + "Before you can enjoy the benefits of the site, please take the time to confirm your email. Please follow this link:"
                + Environment.NewLine + _baseURL + "/public/confirmation/" + uniqueId + Environment.NewLine + Environment.NewLine;
            model.Message += requestModel.Message;

            model.To = requestModel.Email;

            Send(model);

            if (model != null)
            {
                result = true;
            }

            return result;
        }
        public HttpResponseMessage SendComfirmEmail(VerifyEmailRequest model)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            BaseResponse response = null;
            response = new SuccessResponse();

            HttpStatusCode code = HttpStatusCode.OK;

            ApplicationUser userVerification = _userService.GetUser(model.Email);

            if (userVerification == null)
            {
                response = new ErrorResponse("Cannot find a user with that email.");
                code = HttpStatusCode.BadRequest;
            }

            string userId = userVerification.Id;
            TokensRequest request = new TokensRequest();
            request.UserId = userId;
            request.Token = Guid.NewGuid();
            request.TokenTypeId = 2;

            ItemResponse<int> tokenAddResponse = new ItemResponse<int>();
            tokenAddResponse.Item = TokensService.Insert(request, userId);

            if (tokenAddResponse.Item <= 0)
            {
                response = new ErrorResponse("A new token was not inserted.");
                code = HttpStatusCode.BadRequest;
            }

            Guid uniqueId = request.Token;
            EmailRequest emailRequest = new EmailRequest();
            emailRequest.Email = model.Email;
            emailRequest.Subject = "Confirm Email";
            bool emailSent = MailService.ConfirmationEmail(emailRequest, uniqueId);

            if (!emailSent)
            {
                response = new ErrorResponse("The confirmation email failed to send.");
                code = HttpStatusCode.BadRequest;
            }

            return Request.CreateResponse(code, response);
        }
        public HttpResponseMessage forgotPassword(VerifyEmailRequest model)
        {
            if (!ModelState.IsValid)
            {
                return Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState);
            }

            SuccessResponse response = new SuccessResponse();
            ApplicationUser userVerification = _userService.GetUser(model.Email);

            if (userVerification == null)
            {
                ErrorResponse er = new ErrorResponse("Cannot find a user with that email.");
                return Request.CreateResponse(HttpStatusCode.BadRequest, er);
            }

            string userId = userVerification.Id;
            TokensRequest request = new TokensRequest();
            request.UserId = userId;
            request.Token = Guid.NewGuid();
            request.TokenTypeId = 1;

            ItemResponse<int> tokenAddResponse = new ItemResponse<int>();
            tokenAddResponse.Item = TokensService.Insert(request, userId);

            if (tokenAddResponse.Item <= 0)
            {
                ErrorResponse er = new ErrorResponse("A new token was not inserted.");
                return Request.CreateResponse(HttpStatusCode.BadRequest, er);
            }

            Guid uniqueId = request.Token;
            EmailRequest emailRequest = new EmailRequest();
            emailRequest.Email = model.Email;
            emailRequest.Subject = "Password Reset";
            bool emailSent = MailService.resetPasswordEmail(emailRequest, uniqueId);

            if (!emailSent)
            {
                return Request.CreateResponse(HttpStatusCode.BadRequest, "The reset password email failed to send.");
            }

            return Request.CreateResponse(response);
        }