Exemplo n.º 1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                if (!ValidateCaptcha(Request["g-recaptcha-response"]))
                {
                    ModelState.AddModelError("", "Invalid captcha attempt.");
                    return(View(model));
                }
                var user = new ApplicationUser
                {
                    UserName       = model.UserName,
                    Email          = model.EmailID,
                    FullName       = model.Name,
                    BirthDate      = new DateTime(model.DOB.Year, model.DOB.Month, model.DOB.Day),
                    CreatedOn      = DateTime.Now,
                    Gender         = model.Gender,
                    Active         = true,
                    LastStatusOn   = DateTime.Now,
                    StatusID       = 1,
                    ProfilePicture = "/Profiles/Common/ProfilePic/user.png",
                    CoverPicture   = "/Profiles/Common/ProfileCoverPic/Hydrangeas.jpg"
                };

                try
                {
                    var result = await UserManager.CreateAsync(user, model.Password);

                    if (result.Succeeded)
                    {
                        System.IO.Directory.CreateDirectory(Server.MapPath(@"~\Profiles\" + user.Id + @"\Album\"));
                        System.IO.Directory.CreateDirectory(Server.MapPath(@"~\Profiles\" + user.Id + @"\Album\Icon"));
                        System.IO.Directory.CreateDirectory(Server.MapPath(@"~\Profiles\" + user.Id + @"\Images\"));
                        System.IO.Directory.CreateDirectory(Server.MapPath(@"~\Profiles\" + user.Id + @"\Images\Icon"));
                        System.IO.Directory.CreateDirectory(Server.MapPath(@"~\Profiles\" + user.Id + @"\Audio\"));
                        System.IO.Directory.CreateDirectory(Server.MapPath(@"~\Profiles\" + user.Id + @"\Audio\Icon"));
                        System.IO.Directory.CreateDirectory(Server.MapPath(@"~\Profiles\" + user.Id + @"\Video\"));
                        System.IO.Directory.CreateDirectory(Server.MapPath(@"~\Profiles\" + user.Id + @"\Video\Icon"));
                        System.IO.Directory.CreateDirectory(Server.MapPath(@"~\Profiles\" + user.Id + @"\Temp\"));
                        // Send an email with this link


                        string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                        ExceptionService.LogDebug("After generating token");

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

                        ExceptionService.LogDebug("After email sent");

                        return(RedirectToAction("RequireEmailConfirmation", "Account"));
                    }
                    AddErrors(result);
                }
                catch (Exception ex)
                {
                    ExceptionService.LogError("Error in registration", ex);
                }
                //await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                //return RedirectToAction("Index", "Home");
            }

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