Exemplo n.º 1
0
        public override string APICreateToken(string email_s, string password_s, AppDbContext context)
        {
            ErrInfLogger.LockInstance.InfoLog("APICreateToken launched." + _logInfo);
            Users specifiedUser = context.Users.FirstOrDefault(t => t.Email == email_s);

            if (specifiedUser == null)
            {
                return(null);
            }
            if (Equals(_krypton.DecryptStringAES(specifiedUser.HashPassword, specifiedUser.Salt), password_s))
            {
                DateTime tokenExpiration = DateTime.Now.AddHours(12);

                int userId_i = (specifiedUser.Id.HasValue) ? specifiedUser.Id.Value : -1;

                if (userId_i == -1)
                {
                    return(null);
                }

                int permissionId_i = (specifiedUser.PermissionId.HasValue) ? specifiedUser.PermissionId.Value : 0;

                string token_s = _jwt.ReturnJWT(tokenExpiration, permissionId_i, userId_i);

                specifiedUser.AuthTokenExpiration = tokenExpiration;
                specifiedUser.AuthToken           = token_s;
                context.SaveChanges();
                return(token_s);
            }
            else
            {
                return(null);
            }
        }