Exemplo n.º 1
0
        public Result ActivateUser(int userId, String code)
        {
            String[] errors = ValidateText("User Code", code);
            if(errors.Length > 0) {
                return new Result(errors);
            }

            UserCodeProvider userCodeProvider = new UserCodeProvider();
            int attemptsMade = 0;
            bool isActivated = userCodeProvider.TryActivatingCode(userId, code, out attemptsMade);

            if(!isActivated) {
                if(attemptsMade >= MAX_USERCODE_ATTEMPTS) {
                    UserCode userCode = new UserCode {
                        UserId = userId,
                        DateExpires = DateTime.Now.AddDays(USER_CODE_EXPIRATION_DAYS),
                        Attempts = 0,
                        Code = UserCodeGenerator.GenerateCode((int)userId)
                    };
                    userCodeProvider.CreateNewUserCode(userCode);
                    //TODO: Send Email
                    return new Result(new String[] { Result.INVALID_CODE_MAX_ERROR });
                }
                return new Result(new String[] { Result.INVALID_CODE_ERROR });
            }

            userCodeProvider.RemoveUserCode(userId);
            UserProvider userProvider = new UserProvider();
            userProvider.ActivateUser(userId);

            //TODO: Send Success email
            return new Result();
        }
Exemplo n.º 2
0
 public void CreateNewUserCode(UserCode userCode)
 {
     UserCodeRow userCodeRow = db.SingleOrDefault<UserCodeRow>("WHERE UserId = @0", userCode.UserId);
     if(userCodeRow == null) {
         userCodeRow = new UserCodeRow() { Attempts = 0, UserCode = userCode.Code, UserId = userCode.UserId, DateExpires = userCode.DateExpires };
         db.Insert(userCodeRow);
     }
     else {
         userCodeRow.UserCode = userCode.Code;
         userCodeRow.Attempts = 0;
         userCodeRow.DateExpires = userCode.DateExpires;
         db.Update(userCodeRow);
     }
 }
Exemplo n.º 3
0
        public Result CreateNewUser(UserInfo userInfo, String password)
        {
            String[] errors = ValidateNewUserInfo(userInfo.Name, userInfo.Email, password);
            if(errors.Length > 0) {
                return new Result(errors);
            }

            UserProvider userProvider = new UserProvider();
            if(userProvider.ContainsEmail(userInfo.Email)) {
                return new Result(new String[] { Result.ACCOUNT_EXISTS_ERROR });
            }
            long userId = userProvider.CreateNewUser(userInfo, password);

            UserCode userCode = new UserCode{Attempts = 0, Code = UserCodeGenerator.GenerateCode((int)userId),
                DateExpires = DateTime.Now.AddDays(USER_CODE_EXPIRATION_DAYS), UserId = userId};
            UserCodeProvider userCodeProvider = new UserCodeProvider();
            userCodeProvider.CreateNewUserCode(userCode);

            //TODO : Send Email

            return new Result();
        }