public IActionResult Login([FromBody] UserLoginIn userLogin) { var token = authService.GetEncodedToken(userLogin.Email, userLogin.Password); if (token == null) { Response.StatusCode = 404; return(Json(new JsonMessage("Неправильный логин или пароль", "Такого пользователя не существует"))); } return(Json(token)); }
private string GetTokenSession(UserLoginIn input) { var aa = new HandleSession() { LoggingTime = DateTime.Now, Status = true, Token = Guid.NewGuid().ToString(), userId = Convert.ToInt32(input.IdNumber) }; var a = _context.HandleSessions.Add(new HandleSession() { LoggingTime = DateTime.Now, Status = true, Token = Guid.NewGuid().ToString(), userId = Convert.ToInt32(input.IdNumber) }); _context.SaveChanges(); return(a.Entity.Token); }
//[ProducesResponseType(typeof(CreateUser))] public ActionResult LoginUser(UserLoginIn input) { if (ModelState.IsValid) { User_Data user_Business = new User_Data(); var output = user_Business.Login(input); switch (output.Result) { case (Result.error): return(StatusCode(500, output)); default: return(Ok(output)); } } else { return(BadRequest()); } }
public UserLoginOut Login(UserLoginIn input) { UserLoginOut output = new UserLoginOut() { Result = Result.error, usrLoggued = false }; try { var userInDb = _context.Users.SingleOrDefault(m => m.IdNumber == Convert.ToInt32(input.IdNumber)); if (userInDb != null) { var usr_passEnc = SerializePass(Encoding.UTF8.GetBytes(input.PassWord)); if (usr_passEnc == userInDb.PassWord) { output.Result = Result.success; output.usrLoggued = true; output.token = GetTokenSession(input); } else { output.Result = Result.notFound; output.Message = "Usuario o contraseña incorrecta"; } } else { output.Result = Result.notFound; output.Message = "Usuario o contraseña incorrecta"; } } catch (Exception ex) { output.Message = ex.Message; } return(output); }