示例#1
0
        public ActionResult Register(BusinessRegisterViewModel rvm)
        {
            if (ModelState.IsValid)
            {
                //register
                var appDbContext = new ApplicationDbContext();
                var userStore    = new ApplicationUserStore(appDbContext);
                var userManager  = new ApplicationUserManager(userStore);
                var passwordHash = Crypto.HashPassword(rvm.Password);
                var user         = new ApplicationUser()
                {
                    Email        = rvm.Email,
                    UserName     = rvm.Username,
                    PasswordHash = passwordHash,
                    BusinessName = rvm.BusinessName,
                    City         = rvm.City,
                    CountryID    = rvm.CountryID,
                    Address      = rvm.Address,
                    PhoneNumber  = rvm.Mobile
                };
                IdentityResult result = userManager.Create(user);

                if (result.Succeeded)
                {
                    //role
                    userManager.AddToRole(user.Id, "Business Owner");

                    //login
                    var authenticationManager = HttpContext.GetOwinContext().Authentication;
                    var userIdentity          = userManager.CreateIdentity(user, DefaultAuthenticationTypes.ApplicationCookie);
                    authenticationManager.SignIn(new AuthenticationProperties(), userIdentity);
                }
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ModelState.AddModelError("My Error", "Invalid data");
                return(View(rvm));
            }
        }
示例#2
0
        public async Task <ActionResult> RegisterBusiness(BusinessRegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                Business business = new Business()
                {
                    Public       = false,
                    Name         = model.BusinessName,
                    Schedule     = new Schedule(),
                    BusinessPage = new BusinessPage {
                        PageContent = new PageContent()
                    }
                };
                var user = new ApplicationUser {
                    UserName = model.BusinessName, Email = model.Email, Business = business, MessageBox = new MessageBox()
                };

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

                if (result.Succeeded)
                {
                    var currentUser = UserManager.FindByName(user.UserName);
                    UserManager.AddToRole(currentUser.Id, "Business");
                    new MessageController().MessageFromAdmin(user.UserName, "Witamy na stronie AppoCal. Mamy nadzieję, że nasza aplikacja pomoże Ci uporządkować swoje wizyty. Pamietaj, aby dobrze opisać swoją firmę oraz dodać usługi jakie wykonujesz.");
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // Aby uzyskać więcej informacji o sposobie włączania potwierdzania konta i resetowaniu hasła, odwiedź stronę https://go.microsoft.com/fwlink/?LinkID=320771
                    // Wyślij wiadomość e-mail z tym łączem
                    // 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, "Potwierdź konto", "Potwierdź konto, klikając <a href=\"" + callbackUrl + "\">tutaj</a>");

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

            // Dotarcie do tego miejsca wskazuje, że wystąpił błąd, wyświetl ponownie formularz
            return(View("Register", model));
        }
示例#3
0
 public ActionResult Register2(BusinessRegisterViewModel rvm)
 {
     return(View());
 }