public ActionResult ConfirmUser(string token)
        {
            if (string.IsNullOrWhiteSpace(token))
            {
                return(RedirectToHome());
            }

            var userConfirmationToken = urlSafeSecureDataSerializer
                                        .Deserialize <UserConfirmationToken>(token);

            if (confirmUser(
                    userConfirmationToken.Email,
                    userConfirmationToken.Token))
            {
                seedDataLoader.Load(userConfirmationToken.Email);
                Flash[FlashMessageType.Success] = "Your account is now " +
                                                  "successfully verified.";
            }
            else
            {
                Flash[FlashMessageType.Error] = "Invalid confirmation " +
                                                "token, you may have miss typed the token or the " +
                                                "token has expired.";
            }

            return(RedirectToHome());
        }
Exemplo n.º 2
0
 public Task StartAsync(CancellationToken cancellationToken)
 {
     SetupWsProxy();
     seedDataLoader.Load(false);
     recordingService.Initialize();
     timingSessionService.Initialize();
     return(Task.CompletedTask);
 }
Exemplo n.º 3
0
        public async Task <HttpResponseMessage> Post(CreateUser model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(
                           HttpStatusCode.BadRequest, ModelState));
            }

            var statusCode = MembershipCreateStatus.Success;
            var userName   = model.Email.ToLowerInvariant();
            var token      = string.Empty;

            var requireConfirmation = !IsDebuggingEnabled;

            try
            {
                token = signup(userName, model.Password, requireConfirmation);
            }
            catch (MembershipCreateUserException e)
            {
                statusCode = e.StatusCode;
            }

            if (statusCode == MembershipCreateStatus.Success)
            {
                if (requireConfirmation)
                {
                    var userConfirmationToken = new UserConfirmationToken
                    {
                        Email = userName,
                        Token = token
                    };

                    var securedToken = urlSafeSecureDataSerializer.Serialize(
                        userConfirmationToken);

                    await mailer.UserConfirmationAsync(userName, securedToken);
                }
                else
                {
                    seedDataLoader.Load(userName);
                }

                return(Request.CreateResponse(HttpStatusCode.NoContent));
            }

            switch (statusCode)
            {
            case MembershipCreateStatus.DuplicateUserName:
            case MembershipCreateStatus.DuplicateEmail:
            case MembershipCreateStatus.DuplicateProviderUserKey:
                ModelState.AddModelError(
                    "email",
                    "User with same email already exits.");
                break;

            case MembershipCreateStatus.InvalidUserName:
            case MembershipCreateStatus.InvalidEmail:
                ModelState.AddModelError(
                    "email",
                    "Invalid email address.");
                break;

            case MembershipCreateStatus.InvalidPassword:
                ModelState.AddModelError("password", "Invalid password.");
                break;

            default:
                ModelState.AddModelError(
                    string.Empty,
                    "Unexpected error.");
                break;
            }

            return(Request.CreateErrorResponse(
                       HttpStatusCode.BadRequest, ModelState));
        }