Пример #1
0
        public AuthenticationResult AuthenticateUser(Credentials creds)
        {
            _session = new Session();
              var result = new AuthenticationResult();
              User user = null;
              this.CurrentCredentials = creds;

              if (EmailOrPasswordNotPresent()) {
            result = InvalidLogin(Properties.Resources.EmailOrPasswordMissing);
              } else {
            //find the user
            user = LocateUser();

            //if they're not here, we're done
            if (user == null) {
              result = InvalidLogin(Properties.Resources.InvalidLogin);

              //does the password match?
            } else if (HashedPasswordDoesNotMatch(user)) {
              result = InvalidLogin(Properties.Resources.InvalidLogin);

              //success
            } else {
              //success!
              user.AddLogEntry("Login", "User logged in");
              result.Session = CreateSession(user);

              SetUserLoginStats(user);
              //save changes
              UserAuthenticated(user);

              result.Authenticated = true;
              result.User = user;
              result.Message = Properties.Resources.UserAuthenticated;

              _session.SaveChanges();
            }
              }

              //dispose of this
              _session.Dispose();

              return result;
        }
Пример #2
0
        public AuthenticationResult AuthenticateUserByToken(string token, string ip = "127.0.0.1")
        {
            var result = new AuthenticationResult();
              _session = new Session();

              if (String.IsNullOrWhiteSpace(token)) {
            result = InvalidLogin("No token provided");
              } else {
            this.CurrentCredentials = new Credentials { Token = Guid.Parse(token), IP = ip };

            var user = FindUserByAuthenticationToken();
            if (user == null) {
              result = InvalidLogin("Invalid token");
            } else {
              //success
              user.AddLogEntry("Login", "User logged in by token");
              result.Session = CreateSession(user);
              SetUserLoginStats(user);
              UserAuthenticated(user);

              result.Authenticated = true;
              result.User = user;
              result.Message = Properties.Resources.UserAuthenticated;
              _session.SaveChanges();
            }
              }
              _session.Dispose();
              return result;
        }
Пример #3
0
 public AuthenticationResult Authenticate(Credentials creds)
 {
     return _auth.AuthenticateUser(creds);
 }