public HttpResponseMessage UpdateAccountDetail(HttpRequestMessage request, [FromBody] UserSetup accountModel)
        {
            return(GetHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                UserSetup account = null;

                var securityMode = ConfigurationManager.AppSettings["SecurityMode"].ToString();

                // revalidate all steps to ensure this operation is secure against hacks
                if (accountModel.UserSetupId <= 0)
                {
                    if (securityMode == "UP")
                    {
                        _SecurityAdapter.Initialize();
                        _SecurityAdapter.Register(accountModel.LoginID, "@password",
                                                  propertyValues: new
                        {
                            Name = accountModel.Name,
                            Email = accountModel.Email,
                            MultiCompanyAccess = accountModel.MultiCompanyAccess,
                            LatestConnection = DateTime.Now,
                            Deleted = false,
                            Active = true,
                            CreatedBy = User.Identity.Name,
                            CreatedOn = DateTime.Now,
                            UpdatedBy = User.Identity.Name,
                            UpdatedOn = DateTime.Now,
                        });

                        account = _CoreService.GetUserSetupByLoginID(accountModel.LoginID);
                    }
                    else
                    {
                        accountModel.LatestConnection = DateTime.Now;
                        accountModel.Active = true;
                        accountModel.Deleted = false;
                        accountModel.CreatedBy = User.Identity.Name;
                        accountModel.CreatedOn = DateTime.Now;
                        accountModel.UpdatedBy = User.Identity.Name;
                        accountModel.UpdatedOn = DateTime.Now;

                        account = _CoreService.UpdateUserSetup(accountModel);
                    }
                }
                else
                {
                    account = _CoreService.UpdateUserSetup(accountModel);
                }

                response = request.CreateResponse <UserSetup>(HttpStatusCode.OK, account);

                return response;
            }));
        }
Пример #2
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);
        }
Пример #3
0
        public HttpResponseMessage CreateAccount(HttpRequestMessage request,
                                                 [FromBody] AccountRegisterModel accountRegisterModel)
        {
            return(GetResponseMessage(request, () =>
            {
                HttpResponseMessage response = null;
                if (ValidateRegistrationStep1(request, accountRegisterModel).IsSuccessStatusCode&&
                    ValidateRegistrationStep2(request, accountRegisterModel).IsSuccessStatusCode&&
                    ValidateRegistrationStep3(request, accountRegisterModel).IsSuccessStatusCode)
                {
                    _securityAdapter.Register(accountRegisterModel.LoginEmail, accountRegisterModel.Password, new
                    {
                        FirstName = accountRegisterModel.FirstName,
                        LastName = accountRegisterModel.LastName,
                        Address = accountRegisterModel.Address,
                        City = accountRegisterModel.City,
                        State = accountRegisterModel.State,
                        ZipCode = accountRegisterModel.ZipCode,
                        LoginEmail = accountRegisterModel.LoginEmail,
                        Password = accountRegisterModel.Password,
                        CreditCard = accountRegisterModel.CreditCard,
                        ExpDate = accountRegisterModel.ExpDate
                    });

                    _securityAdapter.Login(accountRegisterModel.LoginEmail, accountRegisterModel.Password, false);
                    response = request.CreateResponse(HttpStatusCode.OK);
                }

                return response;
            }));
        }
Пример #4
0
        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;
            }));
        }
Пример #5
0
        public ActionResult Register(AccountRegisterModel viewModel)
        {
            _SecurityAdapter.Initialize();

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

            // Prepare the identity with the provided information
            var user = new IdentityUser
            {
                UserName = viewModel.Name ?? viewModel.Email,
                Email    = viewModel.Email
            };

            // Try to create a user with the given identity
            try
            {
                _SecurityAdapter.Register(viewModel.LoginID, viewModel.Password,
                                          propertyValues: new
                {
                    Name          = viewModel.Name,
                    Email         = viewModel.Email,
                    LastLoginDate = DateTime.Now,
                    IsLock        = false,
                    Deleted       = false,
                    Active        = true,
                    CreatedBy     = User.Identity.Name,
                    CreatedOn     = DateTime.Now,
                    UpdatedBy     = User.Identity.Name,
                    UpdatedOn     = DateTime.Now,
                });

                //// If the user could not be created
                //if (!result.Succeeded)
                //{
                //    // Add all errors to the page so they can be used to display what went wrong
                //    AddErrors(result);

                //    return View(viewModel);
                //}

                // If the user was able to be created we can sign it in immediately
                // Note: Consider using the email verification proces
                var success = _SecurityAdapter.Login(viewModel.LoginID, viewModel.Password, false);

                return(RedirectToLocal());
            }
            catch (DbEntityValidationException ex)
            {
                // Add all errors to the page so they can be used to display what went wrong
                AddErrors(ex);

                return(View(viewModel));
            }
        }
Пример #6
0
        public HttpResponseMessage CreateUser(HttpRequestMessage request,
                                              [FromBody] CreateNewUserModel passwordModel)
        {
            HttpResponseMessage response = null;

            var tempPassword = Membership.GeneratePassword(8, 1);

            _securityAdapter.Register(passwordModel.Email, tempPassword, new
            {
                FullName = passwordModel.FullName,
                Department_DepartmentId = passwordModel.DepartmentId,
                Title = passwordModel.Title
            });

            Roles.AddUserToRole(passwordModel.Email, "employee");
            response = request.CreateResponse(HttpStatusCode.OK, tempPassword);

            return(response);
        }
Пример #7
0
        public HttpResponseMessage UpdateUser(HttpRequestMessage request, [FromBody] User userModel)
        {
            return(GetHttpResponse(request, () =>
            {
                User user = null;

                if (userModel.UserId == 0)
                {
                    _SecurityAdapter.Initialize();

                    _SecurityAdapter.Register(userModel.LoginID, "P@ssword",
                                              propertyValues: new
                    {
                        FirstName = userModel.FirstName,
                        LastName = userModel.LastName,
                        LoginId = userModel.LoginID,
                        EntityScope = userModel.EntityScope,
                        ScopeCode = userModel.ScopeCode,
                        GroupId = userModel.GroupId,
                        EmployeeCode = userModel.EmployeeCode,
                        Email = userModel.Email,
                        Mobile = userModel.Mobile,
                        LastLoginDate = DateTime.Now,
                        IsLock = false,
                        Deleted = false,
                        Active = true,
                        CreatedBy = "Auto",
                        CreatedOn = DateTime.Now,
                        UpdatedBy = "Auto",
                        UpdatedOn = DateTime.Now,
                    });

                    user = _CoreService.GetUserByLogin(userModel.LoginID);
                }
                else
                {
                    user = _CoreService.UpdateUser(userModel);
                }

                return request.CreateResponse <User>(HttpStatusCode.OK, user);
            }));
        }
 public IHttpActionResult CreatAccount([FromBody] AccountRegisterModel accountModel)
 {
     return(GetHttpResponse(Request, () => {
         if (ValidateRegistrationStep1Inner(accountModel).Count == 0 &&
             ValidateRegistrationStep2Inner(accountModel).Count == 0 &&
             ValidateRegistrationStep3Inner(accountModel).Count == 0)
         {
             var accountRegisterModel = new AccountRegisterModel {
                 FirstName = accountModel.FirstName, LastName = accountModel.LastName,
                 Address = accountModel.Address, City = accountModel.City,
                 State = accountModel.State, ZipCode = accountModel.ZipCode,
                 LoginEmail = accountModel.LoginEmail, CreditCard = accountModel.CreditCard,
                 ExpDate = accountModel.ExpDate.Substring(0, 2) + accountModel.ExpDate.Substring(3, 2)
             };
             _SecurityAdapter.Register(accountModel.Password, accountRegisterModel);
             _SecurityAdapter.Login(accountModel.LoginEmail, accountModel.Password, false);
             return Content(HttpStatusCode.OK, "Account Created");
         }
         else
         {
             return Content(HttpStatusCode.BadRequest, "Account Creation Failed");
         }
     }));
 }