コード例 #1
0
        public HttpResponseMessage GetUser()
        {
            Guid userID = new Guid(User.Identity.Name);

            AccountsApiModel         accountsWebApiModel = new AccountsApiModel();
            TransactionalInformation transaction         = new TransactionalInformation();
            AccountsBusinessService  accountsBusinessService;

            accountsWebApiModel.IsAuthenicated = true;

            accountsBusinessService = new AccountsBusinessService(accountsDataService);
            User user = accountsBusinessService.GetUser(userID, out transaction);

            transaction.ReturnStatus = true;

            if (transaction.ReturnStatus == false)
            {
                accountsWebApiModel.ReturnMessage    = transaction.ReturnMessage;
                accountsWebApiModel.ReturnStatus     = transaction.ReturnStatus;
                accountsWebApiModel.ValidationErrors = transaction.ValidationErrors;
                var badResponse = Request.CreateResponse <AccountsApiModel>(HttpStatusCode.BadRequest, accountsWebApiModel);
                return(badResponse);
            }

            accountsWebApiModel.ReturnStatus = transaction.ReturnStatus;
            accountsWebApiModel.User         = user;

            var response = Request.CreateResponse <AccountsApiModel>(HttpStatusCode.OK, accountsWebApiModel);

            return(response);
        }
コード例 #2
0
        public async Task <IActionResult> Login([FromBody] LoginViewModel model, string returnUrl = null)
        {
            AccountsApiModel accountsWebApiModel = new AccountsApiModel();

            if (ModelState.IsValid)
            {
                var result = await _accountService.Login(model.UserName, model.Password, model.RememberMe);

                if (result.Succeeded)
                {
                    var token = await _accountService.GetLoginToken(model.UserName, model.Password);

                    accountsWebApiModel.User.UserName = model.UserName;
                    accountsWebApiModel.Token         = token;
                    return(new ObjectResult(accountsWebApiModel));
                }
                if (result.RequiresTwoFactor)
                {
                    return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }));
                }
                if (result.IsLockedOut)
                {
                    return(View("Lockout"));
                }
                else
                {
                    return(new ObjectResult("Invalid username or password."));
                }
            }
            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #3
0
ファイル: UserController.cs プロジェクト: huongdoan/Suite
        public AccountsApiModel RegisterUser(UserDTO registerUserDTO)
        {
            //Context.Response.HttpContext.
            AccountsApiModel         accountsWebApiModel = new AccountsApiModel();
            TransactionalInformation transaction         = new TransactionalInformation();

            return(null);
        }
コード例 #4
0
        public HttpResponseMessage Login(HttpRequestMessage request, [FromBody] LoginUserDTO loginUserDTO)
        {
            AccountsApiModel         accountsWebApiModel = new AccountsApiModel();
            TransactionalInformation transaction         = new TransactionalInformation();
            AccountsBusinessService  accountsBusinessService;

            if (loginUserDTO.UserName == null)
            {
                loginUserDTO.UserName = "";
            }
            if (loginUserDTO.Password == null)
            {
                loginUserDTO.Password = "";
            }

            accountsBusinessService = new AccountsBusinessService(accountsDataService);
            User user = accountsBusinessService.Login(
                loginUserDTO.UserName,
                loginUserDTO.Password,
                out transaction);

            if (transaction.ReturnStatus == false)
            {
                accountsWebApiModel.ReturnMessage    = transaction.ReturnMessage;
                accountsWebApiModel.ReturnStatus     = transaction.ReturnStatus;
                accountsWebApiModel.ValidationErrors = transaction.ValidationErrors;
                var badResponse = Request.CreateResponse <AccountsApiModel>(HttpStatusCode.BadRequest, accountsWebApiModel);
                return(badResponse);
            }

            ApplicationInitializationBusinessService initializationBusinessService;

            initializationBusinessService = new ApplicationInitializationBusinessService(applicationDataService);
            List <ApplicationMenu> menuItems = initializationBusinessService.GetMenuItems(true, out transaction);

            if (transaction.ReturnStatus == false)
            {
                accountsWebApiModel.ReturnMessage = transaction.ReturnMessage;
                accountsWebApiModel.ReturnStatus  = transaction.ReturnStatus;
                var badResponse = Request.CreateResponse <AccountsApiModel>(HttpStatusCode.BadRequest, accountsWebApiModel);
                return(badResponse);
            }

            accountsWebApiModel.ReturnStatus   = transaction.ReturnStatus;
            accountsWebApiModel.IsAuthenicated = true;
            accountsWebApiModel.ReturnMessage.Add("Login successful.");
            accountsWebApiModel.MenuItems = menuItems;
            accountsWebApiModel.User      = user;

            FormsAuthentication.SetAuthCookie(user.UserId.ToString(), createPersistentCookie: false);

            var response = Request.CreateResponse <AccountsApiModel>(HttpStatusCode.OK, accountsWebApiModel);

            return(response);
        }
コード例 #5
0
        public dynamic Post([FromBody] LoginViewModel model)
        {
            AccountsApiModel accountsWebApiModel = new AccountsApiModel();

            if (ModelState.IsValid)
            {
                var result = _accountService.Login(model.UserName, model.Password, model.RememberMe).Result;
                if (result.Succeeded)
                {
                    DateTime?expires = DateTime.UtcNow.AddMinutes(10);
                    accountsWebApiModel.User.UserName = model.UserName;
                    accountsWebApiModel.Token         = GetToken(model.UserName, expires);
                    accountsWebApiModel.Authenticated = true;
                    return(new ObjectResult(accountsWebApiModel));
                }
            }
            return(new ObjectResult("Invalid username or password."));
        }
コード例 #6
0
        public HttpResponseMessage UpdateUser(HttpRequestMessage request, [FromBody] UserDTO updateUserDTO)
        {
            Guid userID = new Guid(User.Identity.Name);

            AccountsApiModel         accountsWebApiModel = new AccountsApiModel();
            TransactionalInformation transaction         = new TransactionalInformation();
            AccountsBusinessService  accountsBusinessService;

            accountsWebApiModel.IsAuthenicated = true;

            if (updateUserDTO.FirstName == null)
            {
                updateUserDTO.FirstName = "";
            }
            if (updateUserDTO.LastName == null)
            {
                updateUserDTO.LastName = "";
            }
            if (updateUserDTO.EmailAddress == null)
            {
                updateUserDTO.EmailAddress = "";
            }
            if (updateUserDTO.UserName == null)
            {
                updateUserDTO.UserName = "";
            }
            if (updateUserDTO.Password == null)
            {
                updateUserDTO.Password = "";
            }
            if (updateUserDTO.PasswordConfirmation == null)
            {
                updateUserDTO.PasswordConfirmation = "";
            }

            accountsBusinessService = new AccountsBusinessService(accountsDataService);
            User user = accountsBusinessService.UpdateUser(
                userID,
                updateUserDTO.FirstName,
                updateUserDTO.LastName,
                updateUserDTO.UserName,
                updateUserDTO.EmailAddress,
                updateUserDTO.Password,
                updateUserDTO.PasswordConfirmation,
                out transaction);

            if (transaction.ReturnStatus == false)
            {
                accountsWebApiModel.ReturnMessage    = transaction.ReturnMessage;
                accountsWebApiModel.ReturnStatus     = transaction.ReturnStatus;
                accountsWebApiModel.ValidationErrors = transaction.ValidationErrors;
                var badResponse = Request.CreateResponse <AccountsApiModel>(HttpStatusCode.BadRequest, accountsWebApiModel);
                return(badResponse);
            }

            accountsWebApiModel.ReturnStatus = transaction.ReturnStatus;
            accountsWebApiModel.ReturnMessage.Add("User successful updated.");

            var response = Request.CreateResponse <AccountsApiModel>(HttpStatusCode.OK, accountsWebApiModel);

            return(response);
        }