Exemplo n.º 1
0
        public HttpResponseMessage IsValid(Guid id)
        {
            ItemResponse <bool> response = new ItemResponse <Boolean>();

            response.Item = UserTokensService.IsValid(id);

            return(Request.CreateResponse(response));
        }
Exemplo n.º 2
0
        public HttpResponseMessage Get(Guid id)
        {
            ItemResponse <Token> response = new ItemResponse <Token>();

            response.Item = UserTokensService.Get(id);

            return(Request.CreateResponse(response));
        }
Exemplo n.º 3
0
        public HttpResponseMessage AddUserTokens(UserTokensAddRequest model)
        {
            // if the Model does not pass validation, there will be an Error response returned with errors
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            ItemResponse <Guid> response = new ItemResponse <Guid>();

            response.Item = UserTokensService.Add(model);

            return(Request.CreateResponse(response));
        }
Exemplo n.º 4
0
        public HttpResponseMessage RegisterAdd(IdentityUser model)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); //if email is NOT valid return error response
            }
            try
            {
                IdentityUser register = UserService.CreateUser(model.UserName, model.Email, model.PasswordHash);

                if (register != null)
                {
                    UserTokensAddRequest tokensAddRequest = new UserTokensAddRequest();

                    tokensAddRequest.UserName  = register.UserName;
                    tokensAddRequest.TokenType = 1;
                    tokensAddRequest.TokenId   = UserTokensService.Add(tokensAddRequest);

                    SendConfirmationEmailRequest request = new SendConfirmationEmailRequest();
                    request.UserName = register.UserName;
                    request.Email    = register.Email;
                    request.Token    = tokensAddRequest.TokenId;

                    Task t = _messagingService.SendConfirmationEmail(request);
                }
                else
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest,
                                                       "Register wasn't successfull Please try again"));
                }
                return(Request.CreateResponse(register));
            }

            catch (IdentityResultException iex)
            {
                ErrorResponse er = new ErrorResponse(iex.Result.Errors);
                return(Request.CreateResponse(HttpStatusCode.BadRequest, er));
            }

            catch (Exception ex)
            {
                ErrorResponse er = new ErrorResponse(ex.Message);
                return(Request.CreateResponse(HttpStatusCode.BadRequest, er));
            }
        }
Exemplo n.º 5
0
        public HttpResponseMessage AddEmail(ForgotPasswordRequest model)
        {
            HttpResponseMessage responseMessage = null;
            BaseResponse        response        = null;

            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); //if email is NOT valid return error response
            }

            ApplicationUser user = UserService.GetUserByEmail(model.Email); //grabs user email


            if (user != null)
            {
                UserTokensAddRequest foo = new UserTokensAddRequest();
                foo.UserName  = user.UserName;
                foo.TokenType = 2;
                Guid tokenId = UserTokensService.Add(foo);

                SendConfirmationEmailRequest request = new SendConfirmationEmailRequest();
                request.UserName = user.UserName;
                request.Email    = user.Email;
                request.Token    = tokenId;

                Task t = _messagingService.SendForgotPasswordEmail(request); //calling it to run
            }
            else
            {
                response        = new ErrorResponse("I'm sorry, but your email can't be found, Please use correct Email");
                responseMessage = Request.CreateResponse(HttpStatusCode.BadRequest, response);
                return(responseMessage);
            }

            return(Request.CreateResponse(user));
        }
Exemplo n.º 6
0
        public HttpResponseMessage ConfirmEmail(Guid tokenId)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
            }

            bool tokenIsValid = UserTokensService.IsValid(tokenId);

            if (!tokenIsValid)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Request token is invalid or expired."));
            }

            // Attempt to set AspNetUsers.EmailConfirmed value = true and insert
            // new record in Users table
            bool confirmSuccess = _userDataService.ConfirmEmail(tokenId);

            if (!confirmSuccess)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Failed to confirm registration."));
            }
            return(Request.CreateResponse(new SucessResponse()));
        }