Ejemplo n.º 1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    var userContext = new UserDbContext();
                    var userId      = SignInManager.AuthenticationManager.AuthenticationResponseGrant.Identity.GetUserId();
                    userContext.Users.Add(new UserModel {
                        UserId            = userId,
                        FirstName         = model.FirstName,
                        LastName          = model.LastName,
                        Gender            = model.Gender,
                        SexualOrientation = model.SexualOrientation,
                        BirthDate         = model.BirthDate.Value,
                        ProfilePicUrl     = model.ProfilePicUrl,
                        ZodiacSign        = model.ZodiacSign,
                        Country           = model.Country,
                        ActiveUser        = 1
                    });

                    try {
                        userContext.SaveChanges();
                    } catch (DbEntityValidationException e) {
                        foreach (var eve in e.EntityValidationErrors)
                        {
                            Debug.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                                            eve.Entry.Entity.GetType().Name, eve.Entry.State);
                            foreach (var ve in eve.ValidationErrors)
                            {
                                Debug.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                                ve.PropertyName, ve.ErrorMessage);
                            }
                        }
                    }
                    // For more information on how to enable account confirmation and password reset please visit https://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("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            ViewBag.CountryList = GetList.Countries();
            ViewBag.ZodiacList  = GetList.ZodiacSigns();
            ViewBag.GenderList  = GetList.Genders();
            ViewBag.SexOrList   = GetList.SexualOrientations();
            return(View(model));
        }
Ejemplo n.º 2
0
 public ActionResult Register()
 {
     ViewBag.CountryList = GetList.Countries();
     ViewBag.ZodiacList  = GetList.ZodiacSigns();
     ViewBag.GenderList  = GetList.Genders();
     ViewBag.SexOrList   = GetList.SexualOrientations();
     return(View());
 }
Ejemplo n.º 3
0
        // GET: Profile
        public ActionResult Index()
        {
            var userContext = new UserDbContext();
            var userId      = User.Identity.GetUserId();
            var currentUser = userContext.Users.FirstOrDefault(u => u.UserId == userId);

            ViewBag.CountryList = GetList.Countries();
            ViewBag.ZodiacList  = GetList.ZodiacSigns();
            ViewBag.GenderList  = GetList.Genders();
            ViewBag.SexOrList   = GetList.SexualOrientations();

            return(View(new UserModel {
                FirstName = currentUser?.FirstName,
                LastName = currentUser?.LastName,
                Gender = currentUser?.Gender,
                SexualOrientation = currentUser?.SexualOrientation,
                BirthDate = (DateTime)currentUser?.BirthDate,
                ProfilePicUrl = currentUser?.ProfilePicUrl,
                ZodiacSign = currentUser?.ZodiacSign,
                Country = currentUser?.Country,
                ActiveUser = currentUser?.ActiveUser
            }));
        }