Ejemplo n.º 1
0
        public async Task<ActionResult> Register(RegisterViewModel registerViewModel)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = registerViewModel.Email, Email = registerViewModel.Email };
                var result = await UserManager.CreateAsync(user, registerViewModel.Password);
                if (result.Succeeded)
                {
                    var lmsUser = new LmsUser();
                    lmsUser.Email = registerViewModel.Email;
                    lmsUser.FirstName = registerViewModel.FirstName;
                    lmsUser.LastName = registerViewModel.LastName;
                    lmsUser.AspId = user.Id;
                    lmsUser.GradeLevelId = registerViewModel.GradeLevelId;
                    lmsUser.SuggestedRole = registerViewModel.SuggestedRole;

                    var lmsResponse = _lmsUserManager.CreateUser(lmsUser);

                    if (!lmsResponse.Success)
                    {
                        ViewBag.ErrorMsg = lmsResponse.Message;
                        return View("Error");
                    }



                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return RedirectToAction("NotApprovedYet", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            var gradeLevelResponse = _lmsUserManager.GetAllGradeLevels();
            if (gradeLevelResponse.Success)
            {
                var vm = new LoginRegistrationVM();
                vm.RegisterViewModel = registerViewModel;
                vm.RegisterViewModel.PopulateLists(gradeLevelResponse.Data);
                return View("~/Views/Home/Index.cshtml", vm);
            }
            else
            {
                ViewBag.ErrorMsg = gradeLevelResponse.Message;
                return View("Error");
            }
        }
Ejemplo n.º 2
0
        public async Task<ActionResult> Register(RegisterViewModel RegisterViewModel)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser { UserName = RegisterViewModel.Email, Email = RegisterViewModel.Email };
                var result = await UserManager.CreateAsync(user, RegisterViewModel.Password);

                if (result.Succeeded)
                {
                    var lmsUser = new LmsUser();
                    lmsUser.Email = RegisterViewModel.Email;
                    lmsUser.FirstName = RegisterViewModel.FirstName;
                    lmsUser.LastName = RegisterViewModel.LastName;
                    lmsUser.ID = user.Id;
                    lmsUser.GradeLevelID = RegisterViewModel.GradeLevelID;
                    lmsUser.SuggestedRole = RegisterViewModel.SuggestedRole;

                    _lmsUserManager.Create(lmsUser);

                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return RedirectToAction("NotApprovedYet", "Home");
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            //return RedirectToAction("Home",RegisterViewModel);
            return View();
        }
Ejemplo n.º 3
0
 //public List<SelectListItem> GradeLevels { get; set; }
 public LoginRegistrationVM()
 {
     LoginViewModel = new LoginViewModel();
     RegisterViewModel = new RegisterViewModel();
 }