コード例 #1
0
        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());
        }
コード例 #2
0
        //[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)));
            }
        }
コード例 #3
0
        //[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)));
            }
        }
コード例 #4
0
 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();
     }
 }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
 public string GenerateToken(LoginModelClass login, string type)
 {
     return(loginRepository.GenerateToken(login, type));
 }
コード例 #7
0
 public LoginModelClass UpdateLoginUser(LoginModelClass login)
 {
     return(loginRepository.UpdateLoginUser(login));
 }
コード例 #8
0
 public LoginModelClass AddLoginDetails(LoginModelClass login)
 {
     return(loginRepository.AddLoginDetails(login));
 }