Exemplo n.º 1
0
 public AuthenticationVM AuthByLogin(string email, string password)
 {
     AuthenticationVM vm = null;
     using (var uow = new UnitOfWork())
     {
         var user = uow.UserRepository.GetByEmail(email)
             .SingleOrDefault(u=>u.Password == password);
         if (user != null)
         {
             Token token = CreateToken(user);
             vm = new AuthenticationVM();
             vm.Key = token.Key;
             vm.UserId = user.Id;
         }
     }
     return vm;
 }
Exemplo n.º 2
0
 private AuthenticationVM AuthByKey(string key)
 {
     AuthenticationVM vm = null;
     using (var uow = new UnitOfWork())
     {
         Token token = uow.TokenRepository.GetByKey(key).SingleOrDefault();
         if (token != null)
         {
             if ((DateTime.Now - token.Issued) > Settings.GetAuthExpiration())
             {
                 throw new ExpiredAuthenticationException();
             }
             else
             {
                 vm = new AuthenticationVM();
                 vm.Key = token.Key;
                 vm.UserId = token.UserId;
             }
         }
     }
     return vm;
 }