public async Task <IActionResult> LoginAsync([FromBody] LoginModelClass login) { if (ModelState.IsValid && login != null) { var user = _context.Users.FirstOrDefault(m => m.username == login.username); if (login.password != user.password) { return(Unauthorized()); } else { var claims = new[] { new Claim(JwtRegisteredClaimNames.Sub, login.username), new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()) }; var token = new JwtSecurityToken ( issuer: _configuration["Token:Issuer"], audience: _configuration["Token:Audience"], claims: claims, expires: DateTime.UtcNow.AddDays(30), notBefore: DateTime.UtcNow, signingCredentials: new SigningCredentials(new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_configuration["Token:Key"])), SecurityAlgorithms.HmacSha256) ); return(Ok(new { token = new JwtSecurityTokenHandler().WriteToken(token) })); } } return(BadRequest()); }
//[Route("LoginUP")] public IActionResult AddUserLogin(LoginModelClass login) { var userResult = this.loginManager.AddLoginDetails(login); try { if (userResult != null) { return(this.Ok(new Response(HttpStatusCode.OK, "The Data", userResult))); } return(this.NotFound(new Response(HttpStatusCode.NotFound, "Parking Data Not Found", userResult))); } catch (Exception) { return(this.BadRequest(new Response(HttpStatusCode.BadRequest, "List of Parking not displayed", null))); } }
//[Route("Login")] public IActionResult UserLoginData(LoginModelClass user) { var userResult = loginManager.AddLoginDetails(user); try { if (userResult != null) { var jsonToken = loginManager.GenerateToken(userResult, "User"); return(Ok(new Response(HttpStatusCode.OK, "login done successfully", jsonToken))); } return(NotFound(new Response(HttpStatusCode.NotFound, "List not fount", userResult))); } catch (System.Exception) { return(BadRequest(new Response(HttpStatusCode.BadRequest, "List canot display", null))); } }
public LoginModelClass UpdateLoginUser(LoginModelClass login) { try { SqlCommand sqlCommand = new SqlCommand("sp_AddUserLogin", sqlConnection); sqlCommand.Parameters.AddWithValue("@Email", login.Email); sqlCommand.Parameters.AddWithValue("@password", login.Password); sqlConnection.Open(); sqlCommand.ExecuteNonQuery(); sqlConnection.Close(); return(login); } catch (Exception e) { throw new Exception("Login Details Added" + e); } finally { sqlConnection.Close(); } }
public string GenerateToken(LoginModelClass login, string type) { try { var symmetricSecuritykey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["Jwt:Key"])); var signingCreds = new SigningCredentials(symmetricSecuritykey, SecurityAlgorithms.HmacSha256); var claims = new List <Claim>(); claims.Add(new Claim("Email", login.Email.ToString())); claims.Add(new Claim("Password", login.Password.ToString())); var token = new JwtSecurityToken(configuration["Jwt:Issuer"], configuration["Jwt:Issuer"], claims, expires: DateTime.Now.AddHours(120), signingCredentials: signingCreds); return(new JwtSecurityTokenHandler().WriteToken(token)); } catch (Exception ex) { throw new Exception(ex.Message); } }
public string GenerateToken(LoginModelClass login, string type) { return(loginRepository.GenerateToken(login, type)); }
public LoginModelClass UpdateLoginUser(LoginModelClass login) { return(loginRepository.UpdateLoginUser(login)); }
public LoginModelClass AddLoginDetails(LoginModelClass login) { return(loginRepository.AddLoginDetails(login)); }