Exemplo n.º 1
0
        //[ValidateAntiForgeryToken]
        public async Task<ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new OkbUser
                {
                    UserName = model.Email,
                    Email = model.Email,
                    JoinDate = DateTime.Now,
                    LastLoginDate = DateTime.Now
                };

                var profile = new Profile
                {
                    Gender = model.Gender,
                    LookingForGender = model.LookingForGender,
                    Birthdate = model.Birthdate,
                    Nickname = model.Nickname,
                    LocationId1 = model.LocationId1,
                    LocationId2 = model.LocationId2,
                    UserId = user.Id
                };

                user.Profile = profile;

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

                if (result.Succeeded)
                {
                    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>");

                    //Update activity feed
                    var profileId = _profileRepo.GetProfileId(user.Id);
                    _feedRepo.JoinedActivity(profileId);

                    return RedirectToAction("Index", "Home");
                }

                //AddErrors(result);
            }

            // If we got this far, something failed, redisplay form 
            // Re-populate model with provinces           
            var prov = _locationRepo.GetProvinces();
            model.JsonProvinces = JsonConvert.SerializeObject(prov);
            return View(model);
        }
Exemplo n.º 2
0
        public ActionResult Register()
        {
            if (Request.IsAuthenticated)
            {
                return Redirect("/home");
            }

            var provList = _locationRepo.GetProvinces();

            var json = JsonConvert.SerializeObject(provList);

            var vm = new RegisterViewModel();
            vm.JsonProvinces = json;

            //ViewBag.JsonProvinces = json;

            return View(vm);
        }