public ActionResult Register(RegisterModel model, string returnUrl, bool captchaValid)
        {
            //check whether registration is allowed
            if (AppSettings.Get <bool>("UserRegistrationDisabled"))
            {
                return(RedirectToRoute("RegisterResult", new { resultId = (int)UserRegistrationType.Disabled }));
            }

            if (_workContext.CurrentStudent.IsRegistered())
            {
                //Already registered customer.
                _authenticationService.SignOut();
            }

            //Create a new record
            _workContext.CurrentStudent = CreateNewStudentObject();

            var student = _workContext.CurrentStudent;

            //validate CAPTCHA
            if (AppSettings.Get <bool>("CaptchaEnabled") && !captchaValid)
            {
                ModelState.AddModelError("", "Wrong Captcha");
            }

            if (ModelState.IsValid)
            {
                model.Username = model.Username.Trim();

                var registrationRequest = new StudentRegistrationRequest(_workContext.CurrentStudent ?? new Student(), model.Username, model.Password);
                var registrationResult  = _studentRegistrationService.RegisterStudent(registrationRequest);
                if (registrationResult.Success)
                {
                    //activity log
                    _studentActivityService.InsertActivity("Game.Registration", "ActivityLog.Game.Registration", student);

                    //login student now
                    _authenticationService.SignIn(student, true);

                    //send customer welcome message
                    var redirectUrl = Url.Action("RegisterResult", new { resultId = (int)UserRegistrationType.Standard });
                    if (!String.IsNullOrEmpty(returnUrl) && Url.IsLocalUrl(returnUrl))
                    {
                        redirectUrl = _webHelper.ModifyQueryString(redirectUrl, "returnurl=" + HttpUtility.UrlEncode(returnUrl), null);
                    }
                    return(Redirect(redirectUrl));
                }

                //errors
                foreach (var error in registrationResult.Errors)
                {
                    ModelState.AddModelError("", error);
                }
            }

            //If we got this far, something failed, redisplay form
            return(View(model));
        }