Пример #1
0
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid  && AccountService.IsAvailableUser(model.Email))
                {
                    //Create user
                    var user = AccountService.CreateUser(model);

                    //Call the authenticate
                    AuthenticateUser(user.Id, user.FirstName, user.LastName, user.Email, user.FacebookId, user.AccessToken);

                    //Redirect to profile info
                    return RedirectToAction("Index", "Home");

                }

                // If we got this far, something failed, redisplay form
                return View(model);
        }
Пример #2
0
        public AccountUserDocument CreateUser(RegisterModel model)
        {
            using (IDocumentSession Session = DataDocumentStore.Instance.OpenSession())
            {

                //Persist the new user
                Guid userId = Guid.NewGuid();

                Session.Store(new AccountUserDocument
                {
                    Name = model.Email,
                    Id = String.Format("FacebookTest/Users/{0}", userId),
                    AllowedDatabases = new[] { "*" },

                    Email = model.Email,
                    FirstName = model.FirstName,
                    LastName = model.LastName,
                    FacebookId = 0,
                    Expires = DateTime.Now.AddMonths(1),
                    AccessToken = string.Empty

                }.SetPassword(model.Password));
                Session.SaveChanges();

                //Retrieve user from the document session
                var user = Session.Load<AccountUserDocument>(String.Format("FacebookTest/Users/{0}", userId));

                //Send Validation Email
                //Create return email object
                BCryptService crypto = new BCryptService();
                var identifier = crypto.GenerateToken();
                var returnEmailDocument = new ReturnEmailDocument
                {
                    UserId = user.Id,
                    Email = user.Email,
                    Identifier = identifier,
                    Hash = crypto.Hash(identifier)

                };

                //Creste reset Url
                returnEmailDocument.ResetUrl = ConfigurationManager.AppSettings["BaseUrl"] + "Account/Verify?vac=" + System.Uri.EscapeDataString(returnEmailDocument.Hash);

                //Persist reset object
                Session.Store(returnEmailDocument);
                Session.SaveChanges();

                //Send the email
                if (user != null)
                {
                    EmailModel emailProperties = new EmailModel();
                    emailProperties.ToAddress = user.Email;
                    emailProperties.FirstName = user.FirstName;
                    emailProperties.ReturnUrl = returnEmailDocument.ResetUrl;
                    new MailController().VerificationEmail(emailProperties).Deliver();

                }
                else
                {
                    throw new Exception("User not found by specified email address");
                }

                return user;
            }
        }