Esempio n. 1
0
        public async Task <ActionResult> Register(RegistrationFormViewModel model)
        {
            try
            {
                //Model invalid state it redirects to same view
                if (!ModelState.IsValid)
                {
                    return(View("~/Views/Shared/Widgets/RegistrationFormWidget/_RegistrationFormWidget.cshtml"));
                }
                // Prepares a new user entity using the posted registration data
                var user = new User
                {
                    UserName  = model.Email,
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    Email     = model.Email,
                    Enabled   = true
                };
                // Attempts to create the user in the Kentico database
                var registerResult = new IdentityResult();
                //After taken user detaild it will give some response
                registerResult = await UserManager.CreateAsync(user, model.Password);

                if (registerResult != null)
                {
                    //Already User exists..
                    if (!registerResult.Succeeded && ((string[])registerResult.Errors)[0] != null)
                    {
                        model.ValidationMessage = ((string[])registerResult.Errors)[0];
                        if (model.ValidationMessage != "")
                        {
                            model.ValidationMessage = "User with '" + user.Email + "' already exists";
                        }
                        return(Json(new { ErrorMessage = model.ValidationMessage, RegisterSuccess = "" }));
                    }
                    if (registerResult.Succeeded)
                    {
                        //After user register redirect to registration success page
                        model.ValidationMessage = "Registered Successfully!";
                        return(Json(new { ErrorMessage = model.ValidationMessage }));
                    }
                }
                else
                {
                    //Registration failed
                    model.ValidationMessage = "Registered fail!";
                    return(Json(new { ErrorMessage = model.ValidationMessage }));
                }
            }
            catch (Exception ex)
            {
                //Store the exception deatls into a event log module in kentico
                EventLogProvider.LogException("RegistrationFormController", "RegisterPost", ex);
            }
            return(View("~/Views/Shared/Widgets/RegistrationFormWidget/_RegistrationFormWidget.cshtml", model));
        }
Esempio n. 2
0
 /// <summary>
 /// GET:Display Registration Form in widget
 /// </summary>
 /// <returns></returns>
 public ActionResult Index()
 {
     try
     {
         //Get current page widget properties
         var properties = GetProperties();
         RegistrationFormViewModel model = new RegistrationFormViewModel {
             Visible = properties.Visible, RedirectUrl = properties.RedirectUrl, Title = properties.Title, ButtonText = properties.ButtonText
         };
         return(View("~/Views/Shared/Widgets/RegistrationFormWidget/_RegistrationFormWidget.cshtml", model));
     }
     catch (Exception ex)
     {
         EventLogProvider.LogException("RegistrationFormController", "RegisterGet", ex);
         return(null);
     }
 }