MonkeyFist.Services.Authenticator.AuthenticateUserByToken C# (CSharp) Method

AuthenticateUserByToken() public method

public AuthenticateUserByToken ( string token, string ip = "127.0.0.1" ) : AuthenticationResult
token string
ip string
return AuthenticationResult
        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;
        }

Usage Example

Example #1
0
        public ValidTokenLogin()
        {
            //register the new user...
              var app = new Application("*****@*****.**", "password", "password");
              var result = new Registrator().ApplyForMembership(app);

              var auth = new Authenticator();
              _result = auth.AuthenticateUserByToken(result.NewUser.AuthenticationToken.ToString());
        }