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); }
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)); }
public AccountsApiModel RegisterUser(UserDTO registerUserDTO) { //Context.Response.HttpContext. AccountsApiModel accountsWebApiModel = new AccountsApiModel(); TransactionalInformation transaction = new TransactionalInformation(); return(null); }
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); }
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.")); }
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); }