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; }
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; }