public EmployeeWithDetail GetByUserNameAndPassword(string userName, string password) { EmployeeWithDetail result = null; using (AppDBContext dbContext = new AppDBContext(_config)) { var query = from e in dbContext.Employee from s in dbContext.Sex.Where(x => x.Id == e.SexId).DefaultIfEmpty() where e.UserName == userName && e.Password == password select new EmployeeWithDetail() { ID = e.ID, Name = e.Name, LastName = e.LastName, SexId = e.SexId, Email = e.Email, MobilePhone = e.MobilePhone, TRNationalId = e.TRNationalId, Sex_NameTR = s == null ? String.Empty : s.NameTR, Sex_NameEN = s == null ? String.Empty : s.NameEN, }; result = query.AsNoTracking().FirstOrDefault(); } return(result); }
public static string CreateToken(EmployeeWithDetail employeeWithDetail, string userAuthCodeListAsString) { // https://github.com/jwt-dotnet/jwt#JwtNet // JwtSecret bilgisi config dosyasından okunuyor //string secret = "GQDstcKsx0NHjPOuXOYg5MbeJ1XT0uFiwDVvVBrk"; string secret = ConfigHelper.Jwt_Secret; int expiredTime = 60; var token = new JwtBuilder() .WithAlgorithm(new HMACSHA256Algorithm()) .WithSecret(secret) .AddClaim("expireAsUnixSeconds", DateTimeOffset.UtcNow.AddMinutes(expiredTime).ToUnixTimeSeconds()) .AddClaim("ID", employeeWithDetail.ID) .AddClaim("name", employeeWithDetail.Name) .AddClaim("lastName", employeeWithDetail.LastName) .AddClaim("authCodeListAsString", userAuthCodeListAsString) // kullanıcı yetkileri de eklenir .AddClaim("tokenGuid", Guid.NewGuid().ToString()) .Encode(); return(token); }