public async Task <IHttpActionResult> PostAsync([FromBody] UserLogInModel user) { await Task.Yield(); if (user == null) { return(BadRequest("User can not be empty")); } if (user.NickName == "" || user.Password == "") { return(BadRequest("Nor nickname nor password can be empty")); } var target = ConfigurationManager.AppSettings["LogInIP"]; var request = new HttpRequestMessage(HttpMethod.Post, target); var jsonUser = JsonConvert.SerializeObject(user); var stringContent = new StringContent(jsonUser, UnicodeEncoding.UTF8, "application/json"); request.Content = stringContent; var response = await client.SendAsync(request); if (response.IsSuccessStatusCode) { var returned = await response.Content.ReadAsStringAsync().ConfigureAwait(false); JavaScriptSerializer jsonSerializer = new JavaScriptSerializer(); var contentJson = jsonSerializer.DeserializeObject(returned); return(Ok(contentJson)); } else { return(Content(HttpStatusCode.NotFound, "Bad LogIN")); } }
public ActionResult LogIn(UserLogInModel model) { if (!ModelState.IsValid) { return(View(model)); } var user = _userService.GetDetailsByUsername(model.Username); if (user == null) { ViewBag.Message = $"<span class= 'text-danger'> Incorrect username or password. </span>"; return(View(model)); } if (user.Status != StatusConstants.Active && user.PasswordHash != EncryptionService.HashPassword(model.Password, user.PasswordSalt)) { ViewBag.Message = "Incorrect Username or Password, Please try again."; return(View(model)); } Session[user.Username] = user; SetCookie(user, false); return(RedirectToAction("Dashboard", "Home")); }
public ActionResult LogIn(UserLogInModel user) { if (ModelState.IsValid) { using (nominaDBEntities db = new nominaDBEntities()) { Encrypt pass = new Encrypt(); var encPass = pass.ComputeSha256Hash(user.Password); var db_user = db.User.FirstOrDefault(u => u.Password == encPass && u.Email == user.Email); if (db_user != null) { Session["UserID"] = db_user.Id.ToString(); Session["Role"] = db_user.Role.ToString(); //check if user is admin or final //0 for admin, 1 for final user if (db_user.Role == 0) { return(RedirectToAction("UserAdminModule")); } else { return(RedirectToAction("UserFinalModule", "Nomina", new { id = db_user.Id })); } } else { ModelState.AddModelError("Password", Resources.Strings.LogInError); } } } return(View()); }
public ActionResult AddUser(UserModel user, UserLogInModel uLogIn) { RegisterClient(); if (ModelState.IsValid) { System.Diagnostics.Debug.WriteLine(user.firstName + user.lastName + user.zip + uLogIn.password + uLogIn.email); ServiceReference2.UserTable User = new ServiceReference2.UserTable { firstName = user.firstName, lastName = user.lastName, zip = user.zip, accountType = user.accountType }; ServiceReference2.UserLoginTable ULogIn = new ServiceReference2.UserLoginTable { email = uLogIn.email, password = uLogIn.password }; long created = logOgj.RegisterUser(User, ULogIn); if (created > 0) { RedirectToAction("Login", "LogIn"); } else { ModelState.AddModelError("", "Informatiion input invalid"); } } return(View()); }
public ActionResult Login(UserLogInModel user) { // Check if the Model is valid or not // Check if user exists if (ModelState.IsValid) { string username = user.email; string password = user.password; long ID = authObj.CheckCredentials(username, password); if (ID >= 0) { Session["UserId"] = ID.ToString(); RedirectToAction("contact", "Home"); } else { ModelState.AddModelError("", "Username & password combination is invalid"); } } return(View()); }
public async Task <IActionResult> Login(UserLogInModel model) { if (ModelState.IsValid) { var result = await signInManager.PasswordSignInAsync(model.Email, model.Password, false, false); if (result.Succeeded) { return(Ok()); } } return(RedirectToAction("MainPage", "Main")); }
public async Task <IActionResult> LogIn([FromForm] UserLogInModel userLogIn) { AppUser user = await AppUserManager.FindByNameAsync(userLogIn.UserName); if (user != null) { if (await AppUserManager.CheckPasswordAsync(user, userLogIn.Password)) { await AppSignInManager.SignInAsync(user, isPersistent : true); return(Json(new { success = true })); } } return(Json(new { success = false })); }
public ActionResult LogIn() { if (User.Identity.IsAuthenticated) { Session[User.Identity.Name] = null; return(RedirectToAction("Logout")); } var model = new UserLogInModel { Username = "******", Password = "******" }; return(View(model)); }
public async Task <IHttpActionResult> Delete([FromBody] UserLogInModel userToDelete) { await Task.Yield(); if (userToDelete == null) { return(BadRequest("User can not be empty")); } var wasDeleted = userLogic.DeleteUser(userToDelete.NickName, userToDelete.Password); if (!wasDeleted) { return(ResponseMessage(Request.CreateErrorResponse(HttpStatusCode.NotFound, "The user does not exist in our servers"))); } return(Ok("Deleted")); }
public async Task <IHttpActionResult> PostAsync([FromBody] UserLogInModel user) { await Task.Yield(); if (user == null) { return(BadRequest("User can not be empty")); } if (user.NickName == "" || user.Password == "") { return(BadRequest("Nor nickname nor password can be empty")); } var token = sessionLogic.CreateToken(user.NickName, user.Password); return(new NegotiatedContentResult <string>(HttpStatusCode.Created, token.ToString(), this)); }
public async Task <IActionResult> UserLogInAsync([FromBody] UserLogInModel logInModel) { var user = await userManager.FindUserAsync(logInModel.Email, logInModel.Password); //если юзер не найден , то ответ 400 if (user == null) { return(BadRequest("Can't find this user!")); } // поиск юзера в базе если удачно выдать токен //тестовый набор клаймов, надо добавить таблицу клаймов var claims = new List <Claim> { new Claim(ClaimTypes.Role, user.Status), new Claim(ClaimTypes.Email, user.Email) }; var token = await tokenGenerator.GenerateUserToken(user); return(Ok(token)); //return await tokenGenerator.GenerateJwtToken(claims); }
public HttpResponse Login(UserLogInModel model) { var hashPassword = this.passwordHasher.HashPassword(model.Password); var userId = usersService.GetUserId(model.Username, hashPassword); if (userId == null) { if (usersService.IsUsernameAvailable(model.Username)) { return(Error("Password is wrong!")); } return(Error($"Username '{model.Username}' is not register!")); } this.SignIn(userId); return(Redirect("/Repositories/All")); }
public async Task <IActionResult> LogIn(UserLogInModel loginModel) { if (ModelState.IsValid) { var result = await _chatUserService.TryLogIn( loginModel.Name.Trim(), loginModel.Password.Trim()); if (result.success) { var claims = new List <Claim> { new Claim("UserId", result.user.Id.ToString()), new Claim("UserName", result.user.Name) }; var claimsIdentity = new ClaimsIdentity( claims, CookieAuthenticationDefaults.AuthenticationScheme); var authProperties = new AuthenticationProperties { AllowRefresh = true, ExpiresUtc = DateTimeOffset.UtcNow.AddMinutes(20), IsPersistent = true, }; await HttpContext.SignInAsync( CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal (claimsIdentity), authProperties); _onlineUsers.AddOnlineUser(result.user.Id, result.user.Name); return(RedirectToAction("Index", "Chat")); } } return(View()); }
public static void LogIn(UserLogInModel user) { HttpContext.Current.Session[SessionName] = user; }
public ActionResult LogIn(UserLogInModel model) { LogInResult @out = new LogInResult { result = false }; PasswordError err; if ((model.Email ?? "").Length < 1) { @out.err_msg = "Pleause input email!"; } else if (!Validator.EmailIsValid(model.Email)) { @out.err_msg = "Incorrect email!"; } else if ((model.Password ?? "").Length < 1) { @out.err_msg = "Pleause input password!"; } else if (!Validator.PasswordIsValid(model.Password, out err)) { switch (err) { case PasswordError.Length: @out.err_msg = "Minimum 6 symbols, maximum 12 symbols"; break; case PasswordError.Whitespace: @out.err_msg = "No white space"; break; case PasswordError.Upper: @out.err_msg = "At least 1 upper case letter"; break; case PasswordError.Lover: @out.err_msg = "At least 1 lower case letter"; break; case PasswordError.SpecificSymbol: @out.err_msg = "At least 1 special char"; break; default: @out.err_msg = "ERROR"; break; } } else { AppUser user = UserManager.Find(model.Email, model.Password); if (user != null) { ClaimsIdentity claim = UserManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie); AuthenticationManager.SignOut(); AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = true }, claim); @out.result = true; } else { @out.err_msg = "Incorrect password or login"; } } return(Json(@out)); }