Ejemplo n.º 1
0
        public async Task <ActionResult> Register(TeacherRegisterSubmitModel model)
        {
            if (ModelState.IsValid)
            {
                var uploadDirectory = GlobalConstants.TeachersProfileImagesUploadDirectory;

                model.UploadProfilePhoto(uploadDirectory);

                if (model.RegisterViewModel.ImageUpload == null ||
                    model.RegisterViewModel.ImageUpload.ContentLength == 0)
                {
                    model.RegisterViewModel.ImageUrl = GlobalConstants.DefaultProfileImageUrl;
                }

                var user = new ApplicationUser()
                {
                    UserName = model.RegisterViewModel.UserName,
                    Email    = model.RegisterViewModel.Email,
                    ImageUrl = model.RegisterViewModel.ImageUrl
                };

                IdentityResult result = await this.UserManager.CreateAsync(user, model.RegisterViewModel.Password);

                if (result.Succeeded)
                {
                    this.UserManager.AddToRole(user.Id, GlobalConstants.TeacherRoleName);

                    Teacher teacher = new Teacher();
                    teacher.ApplicationUserId = user.Id;
                    Mapper.Map <TeacherRegisterSubmitModel, Teacher>(model, teacher);
                    this.teacherService.Add(teacher);

                    /*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>");*/

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

                    return(RedirectToAction("Index", "Teachers", new { area = "Administration" }));
                }
                else
                {
                    this.AddErrors(result);
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 2
0
        public ActionResult Register()
        {
            if (!User.IsInRole(GlobalConstants.AdministratorRoleName))
            {
                return(RedirectToAction("Index", "Home", new { area = string.Empty }));
            }

            TeacherRegisterSubmitModel model = new TeacherRegisterSubmitModel();

            model.RegisterViewModel = new RegisterViewModel
            {
                ImageUrl = GlobalConstants.DefaultProfileImageUrl
            };

            return(View(model));
        }