コード例 #1
0
        public System.Web.Mvc.ActionResult SignUp(SignUpViewModel model)
        {
            if (OBSSecurity.SignUpEnabled)
            {
                if (ModelState.IsValid)
                {
                    string strErrorMessage = string.Empty;
                    if (model.ImageFile.IsValidImageFile(out strErrorMessage))
                    {
                        AccountInfo newUser = new AccountInfo();
                        int _nValue = 0;

                        newUser.Email = model.Email;
                        newUser.FirstName = model.FirstName;
                        newUser.LastName = model.LastName;
                        newUser.Password = model.Password;
                        newUser.PhoneNumber = model.PhoneNumber;
                        if (!string.IsNullOrEmpty(model.Age))
                        {
                            int.TryParse(model.Age, out _nValue);
                        }
                        newUser.Age = _nValue;

                        if (model.ImageFile.HasImageFile())
                        {
                            newUser.Picture = new UserImage();
                            newUser.Picture = model.ImageFile.ToUserImage();
                        }

                        if (model.Role == AccountRoles.User)
                        {
                            newUser.Role = AccountRoles.User;
                        }
                        else if (model.Role == AccountRoles.Carer)
                        {
                            newUser.Role = AccountRoles.Carer;
                        }

                        UserPreferences prefs = new UserPreferences();
                        prefs.DocumentFontSize = Constants.DefaultDocumentFontSize;
                        prefs.DocumentFontName = Constants.DefaultDocumentFontName;
                        newUser.Preferences = prefs;
                        newUser.Preferences.SelectedDocumentSimplificationTools = Constants.DefaultSimplificationTools;
                        newUser.Preferences.LineSpacing = Constants.DefaultLineSpacing;

                        string result = OBSDataSource.RegisterUserAccount(newUser);
                        if (string.IsNullOrEmpty(result))
                        {
                            return View("CheckEmail");
                        }
                        else
                        {
                            //TODO SHOW INFO
                            ModelState.AddModelError(string.Empty, result);
                            return View("SignUp", model);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, strErrorMessage);
                        return View("SignUp", model);
                    }
                }
                else
                {
                    return View("SignUp", model);
                }
            }
            else
            {
                return RedirectToAction("Home");
            }
        }
コード例 #2
0
        public System.Web.Mvc.ActionResult SignUp(int SignType)
        {
            if (OBSSecurity.SignUpEnabled)
            {
                ViewData["ShowHead"] = true;

                SignUpViewModel model = new SignUpViewModel();

                if (SignType == 1)
                {
                    model = new SignUpViewModel(AccountRoles.User);
                    return View("SignUp", model);
                }
                else if (SignType == 2)
                {
                    model = new SignUpViewModel(AccountRoles.Carer);
                    return View("SignUp", model);
                }
            }

            return RedirectToAction("Home");
        }