public RTUserModel Userlogin(UserLoginModel user) { try { int status = 0; int FlagsAttribute = 1; if (user.EmailId == null || user.Password == null) { throw new Exception(UserExceptions.ExceptionType.NULL_EXCEPTION.ToString()); } if (user.EmailId == "" || user.Password == "") { throw new Exception(UserExceptions.ExceptionType.EMPTY_EXCEPTION.ToString()); } SqlCommand sqlCommand = new SqlCommand("spGetUserLogin", this.sqlConnectionVariable); sqlCommand.CommandType = CommandType.StoredProcedure; sqlCommand.Parameters.AddWithValue("@EmailID", user.EmailId); user.Password = Encrypt(user.Password).ToString(); sqlCommand.Parameters.AddWithValue("@UserPassword", user.Password); this.sqlConnectionVariable.Open(); SqlDataReader sqlDataReader = sqlCommand.ExecuteReader(); RTUserModel usermodel = new RTUserModel(); while (sqlDataReader.Read()) { status = sqlDataReader.GetInt32(0); if (status > 0) { usermodel.UserId = Convert.ToInt32(sqlDataReader["UserId"]); usermodel.FirstName = sqlDataReader["FirstName"].ToString(); usermodel.LastName = sqlDataReader["LastName"].ToString(); usermodel.EmailId = sqlDataReader["EmailId"].ToString(); usermodel.LocalAddress = sqlDataReader["LocalAddress"].ToString(); usermodel.MobileNumber = sqlDataReader["MobileNumber"].ToString(); usermodel.Gender = sqlDataReader["Gender"].ToString(); usermodel.Role = sqlDataReader["Role"].ToString(); usermodel.DateAndTime = sqlDataReader["ModificationDate"].ToString(); FlagsAttribute = 0; break; } else { break; } } this.sqlConnectionVariable.Close(); if (FlagsAttribute == 0) { return(usermodel); } usermodel = null; return(usermodel); } catch (Exception exception) { throw exception; } }
/// <summary> /// Function For JsonToken Generation. /// </summary> /// <param name="data"></param> /// <returns></returns> private string GenerateJsonWebToken(RTUserModel responseUser) { var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(configuration["Jwt:Key"])); var credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256); var claims = new[] { new Claim(JwtRegisteredClaimNames.Sub, responseUser.FirstName), new Claim(JwtRegisteredClaimNames.Email, responseUser.EmailId), new Claim(ClaimTypes.Role, responseUser.Role), new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()) }; var token = new JwtSecurityToken(configuration["Jwt:Issuer"], configuration["Jwt:Audiance"], claims, expires: DateTime.Now.AddMinutes(120), signingCredentials: credentials ); return(new JwtSecurityTokenHandler().WriteToken(token)); }