Ejemplo n.º 1
0
        public async Task <ActionResult> RegisterOwner(RegisterOwnerViewModel model)
        {
            if (ModelState.IsValid)
            {
                //Checking the register code in the db and delete the code if exists
                if (OwnerRegisterCodeManager.CheckOwnerRegisterCode(model.RegisterCode))
                {
                    var owner = new OwnerUsers {
                        UserName = model.UserName.Trim(' '), Email = model.Email
                    };
                    var result = await UserManager.CreateAsync(owner, model.Password);

                    if (result.Succeeded)
                    {
                        //Send notification to office mail
                        await EmailNotifications.RegiteredUserNotification(owner.UserName, owner.Email, owner.PhoneNumber);

                        var currentUser = await UserManager.FindByNameAsync(owner.UserName);

                        await UserManager.AddToRoleAsync(currentUser.Id, "Owner");

                        // 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(owner.Id);

                        if (Request.Url != null)
                        {
                            var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = owner.Id, code }, Request.Url.Scheme);
                            await EmailNotifications.NoReplyMailService.SendHtmlEmailAsync(owner.Email, "Потвърдете акаунтът си в sProperties", "За да потвърдите регистрацията си натиснете <a href=\"" + callbackUrl + "\">ТУК</a>");
                        }

                        return(RedirectToAction("Login", "Account", new { confirm = "email" }));
                    }
                    AddErrorsToModelState(result);
                }
                else
                {
                    ModelState.AddModelError("RegisterCode", "Invalid Register Code");
                    return(View());
                }
            }

            return(View());
        }
Ejemplo n.º 2
0
        public ActionResult CreateOwnerCode()
        {
            var code = OwnerRegisterCodeManager.AddOwnerRegisterCode();

            return(Json(code, JsonRequestBehavior.AllowGet));
        }