예제 #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();
        }
예제 #2
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();
        }