示例#1
0
        public async Task <ActionResult> Register(RegisterModel model)
        {
            ActionResult response = null;

            bool registerSuccess = false;

            bool validationSuccess = RegisterValidation1(model) is StatusCodeResult &&
                                     await RegisterValidation2(model) is StatusCodeResult;

            if (validationSuccess)
            {
                registerSuccess = await _securityAdapter.Register(model.LoginEmail, model.FirstName, model.LastName, model.Password);
            }

            if (registerSuccess)
            {
                await _securityAdapter.Login(model.LoginEmail, model.Password, model.RememberMe);

                response = StatusCode((int)HttpStatusCode.Created, model.LoginEmail);
            }
            else
            {
                response = StatusCode((int)HttpStatusCode.BadRequest, new List <string> {
                    "Unable to register user"
                });
            }

            return(response);
        }
        public HttpResponseMessage CreateAccount(HttpRequestMessage request, [FromBody] AccountRegisterModel accountModel)
        {
            return(GetHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                // revalidate all steps to ensure this operation is secure against hacks
                if (ValidateRegistrationStep1(request, accountModel).IsSuccessStatusCode&&
                    ValidateRegistrationStep2(request, accountModel).IsSuccessStatusCode&&
                    ValidateRegistrationStep3(request, accountModel).IsSuccessStatusCode)
                {
                    _SecurityAdapter.Register(accountModel.LoginEmail, accountModel.Password,
                                              propertyValues: new
                    {
                        FirstName = accountModel.FirstName,
                        LastName = accountModel.LastName,
                        Address = accountModel.Address,
                        City = accountModel.City,
                        State = accountModel.State,
                        ZipCode = accountModel.ZipCode,
                        CreditCard = accountModel.CreditCard,
                        ExpDate = accountModel.ExpDate.Substring(0, 2) + accountModel.ExpDate.Substring(3, 2)
                    });
                    _SecurityAdapter.Login(accountModel.LoginEmail, accountModel.Password, false);

                    response = request.CreateResponse(HttpStatusCode.OK);
                }

                return response;
            }));
        }
示例#3
0
        //[ValidateAntiForgeryToken]
        public ActionResult Login(AccountLoginModel viewModel)
        {
            _SecurityAdapter.Initialize();

            // Ensure we have a valid viewModel to work with
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            // Verify if a user exists with the provided identity information
            var exist = _SecurityAdapter.UserExists(viewModel.LoginID);

            // If a user was found
            if (exist)
            {
                // Then create an identity for it and sign it in
                var success = _SecurityAdapter.Login(viewModel.LoginID, viewModel.Password, viewModel.RememberMe);

                if (success)
                {
                    // If the user came from a specific page, redirect back to it
                    return(RedirectToLocal(viewModel.ReturnUrl));
                }
            }

            // No existing user was found that matched the given criteria
            ModelState.AddModelError("", "Invalid username or password.");

            // If we got this far, something failed, redisplay form
            return(View(viewModel));
        }
示例#4
0
 public HttpResponseMessage Login(HttpRequestMessage request, [FromBody] AccountLoginModel accountLoginModel)
 {
     return(GetResponseMessage(request, () =>
     {
         HttpResponseMessage response;
         bool success = _securityAdapter.Login(accountLoginModel.LoginEmail, accountLoginModel.Password, accountLoginModel.RememberMe);
         if (success)
         {
             response = request.CreateResponse(HttpStatusCode.OK);
         }
         else
         {
             response = request.CreateErrorResponse(HttpStatusCode.BadRequest, "Unauthorized login");
         }
         return response;
     }));
 }
示例#5
0
        public HttpResponseMessage Login(HttpRequestMessage request, [FromBody] AccountLoginModel accountModel)
        {
            HttpResponseMessage response = null;

            return(GetHttpResponse(request, () => {
                bool login = _securityAdapter.Login(accountModel.LoginEmail, accountModel.Password, accountModel.RememberMe);
                if (login)
                {
                    response = request.CreateResponse(HttpStatusCode.OK);
                }
                else
                {
                    response = request.CreateResponse(HttpStatusCode.Unauthorized, "Login fail");
                }
                return response;
            }));
        }
 public IHttpActionResult  Login(
     [FromBody] AccountLoginModel accountModel)
 {
     return(GetHttpResponse(Request, () => {
         //var cartCount = 0;
         bool success = _SecurityAdapter.Login(accountModel.LoginEmail,
                                               accountModel.Password, accountModel.RememberMe); // ref cartCount,
         if (success)
         {
             return Content(HttpStatusCode.OK, "Authenticated");
         }
         else
         {
             return Content(HttpStatusCode.Unauthorized, "Unauthorized login.");
         }
     }));
 }
示例#7
0
        public HttpResponseMessage Login(HttpRequestMessage request, [FromBody] AccountLoginModel accountModel)
        {
            HttpResponseMessage response = null;

            var success = _securityAdapter.Login(accountModel.LoginEmail, accountModel.Password,
                                                 accountModel.RememberMe);

            if (success)
            {
                response = request.CreateResponse(HttpStatusCode.OK);
            }
            else
            {
                response = request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Unauthorized login.");
            }

            return(response);
        }
        public HttpResponseMessage Login(HttpRequestMessage request, [FromBody] AccountLoginModel accountModel)
        {
            return(GetHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;

                bool success = _SecurityAdapter.Login(accountModel.LoginID, accountModel.Password, accountModel.CompanyCode, accountModel.RememberMe);
                if (success)
                {
                    response = request.CreateResponse(HttpStatusCode.OK);
                }
                else
                {
                    response = request.CreateErrorResponse(HttpStatusCode.Unauthorized, "Unauthorized login.");
                }

                return response;
            }));
        }