Exemplo n.º 1
0
        public AccountUserDocument AddOrUpdateFacebookUser(FbModel model)
        {
            using (IDocumentSession Session = DataDocumentStore.Instance.OpenSession())
            {

                BCryptService crypto = new BCryptService();

                //Get the user by their facebook Id
                var user = Session.Query<AccountUserDocument, AccountUser_ByFacebookId>().Where(x => x.FacebookId == model.FacebookId).SingleOrDefault();

                if (user != null)
                {
                    //User exists, update it
                    user.Name = model.Email;
                    user.FacebookEmail = model.Email;
                    user.AllowedDatabases = new[] { "*" };
                    user.FirstName = model.FirstName;
                    user.LastName = model.LastName;
                    user.AccessToken = model.AccessToken;
                    user.FacebookId = model.FacebookId;
                    user.Expires = model.Expires;
                    user.AccountHash = System.Uri.EscapeDataString(crypto.Hash(model.FacebookId.ToString()));

                    //Save Changes
                    Session.SaveChanges();
                    return user;
                }
                else
                {
                    //No user, create a new one
                    Guid userId = Guid.NewGuid();
                    Session.Store(new AccountUserDocument
                    {

                        Name = model.Email,
                        FacebookEmail = model.Email,
                        Id = String.Format("FacebookTest/Users/{0}", userId.ToString()),
                        AllowedDatabases = new[] { "*" },
                        FirstName = model.FirstName,
                        LastName = model.LastName,
                        AccessToken = model.AccessToken,
                        FacebookId = model.FacebookId,
                        Expires = model.Expires,
                        AccountHash = System.Uri.EscapeDataString(crypto.Hash(model.FacebookId.ToString()))
                    });

                    //Save Changes
                    Session.SaveChanges();
                    return Session.Load<AccountUserDocument>(String.Format("FacebookTest/Users/{0}", userId));

                }

            }
        }
Exemplo n.º 2
0
        public AccountUserDocument AddOrUpdateFacebookUser(FbModel model)
        {
            using (IDocumentSession Session = DataDocumentStore.Instance.OpenSession())
            {
                BCryptService crypto = new BCryptService();


                //Get the user by their facebook Id
                var user = Session.Query <AccountUserDocument, AccountUser_ByFacebookId>().Where(x => x.FacebookId == model.FacebookId).SingleOrDefault();


                if (user != null)
                {
                    //User exists, update it
                    user.Name             = model.Email;
                    user.FacebookEmail    = model.Email;
                    user.AllowedDatabases = new[] { "*" };
                    user.FirstName        = model.FirstName;
                    user.LastName         = model.LastName;
                    user.AccessToken      = model.AccessToken;
                    user.FacebookId       = model.FacebookId;
                    user.Expires          = model.Expires;
                    user.AccountHash      = System.Uri.EscapeDataString(crypto.Hash(model.FacebookId.ToString()));

                    //Save Changes
                    Session.SaveChanges();
                    return(user);
                }
                else
                {
                    //No user, create a new one
                    Guid userId = Guid.NewGuid();
                    Session.Store(new AccountUserDocument
                    {
                        Name             = model.Email,
                        FacebookEmail    = model.Email,
                        Id               = String.Format("FacebookTest/Users/{0}", userId.ToString()),
                        AllowedDatabases = new[] { "*" },
                        FirstName        = model.FirstName,
                        LastName         = model.LastName,
                        AccessToken      = model.AccessToken,
                        FacebookId       = model.FacebookId,
                        Expires          = model.Expires,
                        AccountHash      = System.Uri.EscapeDataString(crypto.Hash(model.FacebookId.ToString()))
                    });

                    //Save Changes
                    Session.SaveChanges();
                    return(Session.Load <AccountUserDocument>(String.Format("FacebookTest/Users/{0}", userId)));
                }
            }
        }
Exemplo n.º 3
0
        public void ProcessForgotPassword(ForgotPasswordModel model)
        {
            using (IDocumentSession Session = DataDocumentStore.Instance.OpenSession())
            {
                //Get user info
                var user = Session.Query <AccountUserDocument>().Where(x => x.Email == model.Email).SingleOrDefault();

                //Create return email object
                BCryptService crypto        = new BCryptService();
                var           identifier    = crypto.GenerateToken();
                var           resetDocument = new ReturnEmailDocument
                {
                    UserId     = user.Id,
                    Email      = user.Email,
                    Identifier = identifier,
                    Hash       = crypto.Hash(identifier),
                    Timestamp  = DateTime.Now
                };

                //Creste reset Url
                resetDocument.ResetUrl = ConfigurationManager.AppSettings["BaseUrl"] + "Account/ResetPassword?prc=" + System.Uri.EscapeDataString(resetDocument.Hash);

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



                //Send the email
                if (user != null)
                {
                    EmailModel emailProperties = new EmailModel();
                    emailProperties.ToAddress = user.Email;
                    emailProperties.FirstName = user.FirstName;
                    emailProperties.ReturnUrl = resetDocument.ResetUrl;
                    new MailController().ForgotPasswordEmail(emailProperties).Deliver();
                }
                else
                {
                    throw new UserNotFoundException("User not found by specified email address");
                }
            }
        }
Exemplo n.º 4
0
        public void ProcessForgotPassword(ForgotPasswordModel model)
        {
            using (IDocumentSession Session = DataDocumentStore.Instance.OpenSession())
            {
                //Get user info
                var user = Session.Query<AccountUserDocument>().Where(x => x.Email == model.Email).SingleOrDefault();

                //Create return email object
                BCryptService crypto = new BCryptService();
                var identifier = crypto.GenerateToken();
                var resetDocument = new ReturnEmailDocument
                {
                    UserId = user.Id,
                    Email = user.Email,
                    Identifier = identifier,
                    Hash = crypto.Hash(identifier),
                    Timestamp = DateTime.Now

                };

                //Creste reset Url
                resetDocument.ResetUrl = ConfigurationManager.AppSettings["BaseUrl"] + "Account/ResetPassword?prc=" + System.Uri.EscapeDataString(resetDocument.Hash);

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

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

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

            }
        }
Exemplo n.º 5
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;
            }
        }
Exemplo n.º 6
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);
            }
        }