示例#1
0
 public void SaveToken(Token token)
 {
     String tokenHash = AES.Encrypt(token.TokenString, token.TokenString + token.UserId);
     TokenRow savedTokenRow = db.SingleOrDefault<TokenRow>(@"WHERE UserId = @0 AND DeviceId = @1", token.UserId, (int)token.DeviceType);
     TokenRow tokenRow = new TokenRow() { DateCreated = DateTime.Now, DateExpires = token.DateExpires, DeviceId = (int)token.DeviceType, Token = tokenHash, UserId = token.UserId };
     if(savedTokenRow == null) {
         db.Insert(tokenRow);
     }
     else {
         tokenRow.TokenId = savedTokenRow.TokenId;
         db.Update(tokenRow);
     }
 }
示例#2
0
        public ObjectValueResult CreateUserApp(Token token, AppType appType)
        {
            bool isValid = isValidToken((int)token.UserId, token.TokenString);
            if(!isValid) {
                return new ObjectValueResult(new String[] { Result.INVALID_TOKEN_ERROR });
            }

            UserAppProvider appProvider = new UserAppProvider();
            UserAppInfo userAppInfo = appProvider.GetUserApp(token.UserId, appType);
            if(userAppInfo != null) {
                return new ObjectValueResult(new String[] { Result.USER_APP_EXISTS_ERROR });
            }

            userAppInfo = appProvider.CreateUserApp(token.UserId, appType);
            if(userAppInfo == null) {
                return new ObjectValueResult(new String[] { APP_CREATION_FAILURE });
            }
            return new ObjectValueResult(userAppInfo);
        }
示例#3
0
        public TokenValueResult AuthenticateUser(UserInfo userInfo, String password, Device device)
        {
            String[] errors = ValidateLoginInfo(userInfo.Email, password);
            if(errors.Length > 0) {
                return new TokenValueResult(errors);
            }

            UserProvider userProvider = new UserProvider();
            long userId = userProvider.GetUserId(userInfo.Email, password);
            if(userId < 0) {
                return new TokenValueResult(new String[] { Result.EMAIL_PW_ERROR });
            }

            if(!userProvider.IsUserActive(userId)) {
                return new TokenValueResult(new String[0]) { NeedsActivation = true, Token = new Token { UserId = userId } };
            }

            Token token = new Token() { TokenString = TokenGenerator.GenerateToken((int)userId), DeviceType = device, DateExpires = GetNewTokenExpirationDate(device), UserId = userId };
            TokenProvider tokenProvider = new TokenProvider();
            tokenProvider.SaveToken(token);

            TokenValueResult tokenValueResult = new TokenValueResult(token);
            return tokenValueResult;
        }
示例#4
0
 public TokenValueResult(Token token)
     : base(true)
 {
     Token = token;
 }
示例#5
0
 public void SaveToken(Token token)
 {
     Save(TOKEN_FILE, token);
 }