예제 #1
0
        public TokenDto GenerateToken(string userName)
        {
            string   token       = Guid.NewGuid().ToString();
            DateTime issuedOn    = DateTime.Now;
            DateTime expiredOn   = DateTime.Now.AddSeconds(_SessionTimeout);
            var      tokendomain = new Token
            {
                UserName  = userName,
                AuthToken = token,
                IssuedOn  = issuedOn,
                ExpiresOn = expiredOn
            };

            using (var db = new A77DbContext())
            {
                //db.Token.Add(tokendomain);
                db.Token.AddOrUpdate(tokendomain);
                db.SaveChanges();
            }
            var tokenDto = new TokenDto
            {
                UserName  = tokendomain.UserName,
                AuthToken = tokendomain.AuthToken,
                ExpiresOn = tokendomain.ExpiresOn,
                IssuedOn  = tokendomain.IssuedOn
            };

            return(tokenDto);
        }
예제 #2
0
 public bool Authenticate(UserLoginDto userInfo)
 {
     userInfo.Password = userInfo.Password.ToMD5Hash();
     using (var db = new A77DbContext())
     {
         if (db.User.Any(u => u.UserName.ToLower() == userInfo.UserName.ToLower() && userInfo.Password == u.Password))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #3
0
        public bool DeleteByUserName(string userName)
        {
            var response = false;

            using (var db = new A77DbContext())
            {
                var tokens = db.Token.Where(t => t.UserName == userName).ToList();
                db.Token.RemoveRange(tokens);
                db.SaveChanges();
                response = true;
            }
            return(response);
        }
예제 #4
0
        public bool Kill(string tokenId)
        {
            var response = false;

            using (var db = new A77DbContext())
            {
                var token = db.Token.Find(tokenId);
                if (token != null)
                {
                    db.Token.Remove(token);
                    db.SaveChanges();
                    response = true;
                }
            }
            return(response);
        }
예제 #5
0
        public bool ValidateToken(string tokenId)
        {
            var response = false;

            using (var db = new A77DbContext())
            {
                var token = db.Token.SingleOrDefault(t => t.AuthToken == tokenId && t.ExpiresOn > DateTime.Now);
                if (token != null && !(token.ExpiresOn < DateTime.Now))
                {
                    token.ExpiresOn =
                        token.ExpiresOn.AddSeconds(_SessionTimeout);
                    db.SaveChanges();
                    response = true;
                }
            }
            return(response);
        }
예제 #6
0
        public GetDSUserResponse GetDSUsers()
        {
            var response = new GetDSUserResponse();

            response.Success = false;
            using (var db = new A77DbContext())
            {
                var users = db.User.ToList();
                response.Data = new List <ViewUserDto>();
                foreach (var user in users)
                {
                    response.Data.Add(new ViewUserDto
                    {
                        UserName = user.UserName,
                        Code     = user.Code,
                        Email    = user.Email,
                        FullName = user.FullName
                    });
                }
                response.Success = true;
            }
            return(response);
        }