Exemplo n.º 1
0
 public WritaUser GetUserByEmail(WritaUser u)
 {
     using (var session = docStore.OpenSession())
     {
         return(session.Query <WritaUser>().AsQueryable().Where(w => w.EmailAddress == u.EmailAddress).SingleOrDefault());
     }
 }
Exemplo n.º 2
0
 public WritaUser GetUserById(WritaUser u)
 {
     using (var session = docStore.OpenSession())
     {
         WritaUser ux = session.Load <WritaUser>(u.Id);
         return(ux);
     }
 }
Exemplo n.º 3
0
        public WritaUser UpdateUser(WritaUser u)
        {
            var db    = new WritaBlogContext();
            var euser = db.WritaUsers.AsQueryable().Where(w => w.Id == u.Id).SingleOrDefault();

            euser.UserPasswordEncrypted = u.UserPasswordEncrypted;
            db.SaveChanges();
            return(euser);
        }
Exemplo n.º 4
0
        public WritaUser CreateUser(WritaUser u)
        {
            var db = new WritaBlogContext();

            u.Id = System.Guid.NewGuid().ToString();
            db.WritaUsers.Add(u);
            db.SaveChanges();
            return(u);
        }
Exemplo n.º 5
0
 public WritaUser CreateUser(WritaUser u)
 {
     using (var session = docStore.OpenSession())
     {
         u.Id = System.Guid.NewGuid().ToString();
         session.Store(u);
         session.SaveChanges();
         return(u);
     }
 }
Exemplo n.º 6
0
        public string Update(PostUpdate u)
        {
            WritaUser user = _dbhelper.GetUserById(new WritaUser()
            {
                Id = User.Identity.Name
            });
            var post = _dbhelper.GetPostFromId(u.postid);

            post.PostTitle              = u.posttitle;
            post.PostLastEditedAuthor   = user.UserFullName;
            post.PostLastEditedAuthorID = User.Identity.Name;
            post.PostContent            = u.postmarkdown;
            _dbhelper.UpdatePost(post);
            return(u.posttitle);
        }
Exemplo n.º 7
0
        public string AddUser(AddUserRequest a)
        {
            var       newEncpassword = BCrypt.Net.BCrypt.HashPassword(a.Password, 13);
            WritaUser newUser        = new WritaUser()
            {
                EmailAddress          = a.EmailAddress,
                DateRegistered        = DateTime.Now,
                DateLastLogin         = DateTime.Now,
                UserFullName          = a.UserFullName,
                UserPasswordEncrypted = newEncpassword,
                UserIpAddress         = ""
            };

            WritaUser u = _dbhelper.CreateUser(newUser);

            return("User " + a.EmailAddress + " was created");
        }
Exemplo n.º 8
0
        public string CreatePost(string PostTitle, string PostMarkdown, string poststartdate)
        {
            WritaPost checkexists = _dbhelper.GetPostFromSlug(PostTitle.Replace(" ", "-").ToLower());

            if (checkexists == null)
            {
                WritaUser u = _dbhelper.GetUserById(new WritaUser()
                {
                    Id = User.Identity.Name
                });

                WritaPost post = new WritaPost();
                post.PostAuthorID           = User.Identity.Name;
                post.PostAuthor             = u.UserFullName;
                post.PostLastEditedAuthor   = u.UserFullName;
                post.PostLastEditedAuthorID = User.Identity.Name;
                post.Homepage       = false;
                post.PostSlug       = PostTitle.Replace(" ", "-").ToLower();
                post.PostTitle      = PostTitle;
                post.PostType       = WritaPostType.BLOGPOST;
                post.PostStatus     = WritaPostStatus.DRAFT;
                post.PostContent    = PostMarkdown;
                post.PostThumbnail  = "/content/logo.jpg";
                post.PostCreated    = DateTime.Now;
                post.PostLastEdited = DateTime.Now;

                DateTime dateValue;
                if (DateTime.TryParse(poststartdate, out dateValue))
                {
                    post.PostStartDate = dateValue;
                }
                else
                {
                    post.PostStartDate = DateTime.Now;
                }

                _dbhelper.CreatePost(post);
                RebuildRoutes.Rebuild(true, _dbhelper);

                return("Success");
            }
            else
            {
                return("That post title has been used before, it must be unique.");
            }
        }
Exemplo n.º 9
0
        public WritaUser UpdateUser(WritaUser u)
        {
            var ux = database.GetCollection <WritaUser>("Users").AsQueryable().Where(w => w.Id == u.Id).SingleOrDefault();

            ux.UserPasswordEncrypted = u.UserPasswordEncrypted;
            if (u.EmailAddress != ux.EmailAddress)
            {
                ux.EmailAddress = u.EmailAddress;
            }
            if (u.UserFullName != ux.UserFullName)
            {
                ux.UserFullName = u.UserFullName;
            }
            if (u.UserType != ux.UserType)
            {
                ux.UserType = u.UserType;
            }
            database.GetCollection <WritaUser>("Users").Save(ux);
            return(u);
        }
Exemplo n.º 10
0
 public WritaUser UpdateUser(WritaUser u)
 {
     using (var session = docStore.OpenSession())
     {
         WritaUser ux = session.Load <WritaUser>(u.Id);
         ux.UserPasswordEncrypted = u.UserPasswordEncrypted;
         if (u.EmailAddress != ux.EmailAddress)
         {
             ux.EmailAddress = u.EmailAddress;
         }
         if (u.UserFullName != ux.UserFullName)
         {
             ux.UserFullName = u.UserFullName;
         }
         if (u.UserType != ux.UserType)
         {
             ux.UserType = u.UserType;
         }
         session.SaveChanges();
         return(ux);
     }
 }
Exemplo n.º 11
0
        public string Updatesettings(WritaPost u)
        {
            ValidationResult results = ValidationHelper.ValidateWritaPost(u, _dbhelper);

            if (results.IsValid)
            {
                WritaUser user = _dbhelper.GetUserById(new WritaUser()
                {
                    Id = User.Identity.Name
                });
                WritaPost x = _dbhelper.GetPostFromId(u.PostId);
                x.PostSlug               = StringTools.ReplaceBadInUrl(u.PostSlug);
                x.PostTitle              = u.PostTitle;
                x.PostRedirect           = u.PostRedirect;
                x.PostType               = u.PostType;
                x.PostStatus             = u.PostStatus;
                x.PostCreated            = u.PostCreated;
                x.PostSummary            = u.PostSummary;
                x.PostThumbnail          = u.PostThumbnail;
                x.PostParent             = u.PostParent;
                x.PostLastEditedAuthorID = User.Identity.Name;
                x.PostLastEditedAuthor   = user.UserFullName;
                x.Featured               = u.Featured;

                _dbhelper.UpdatePost(x);
                RebuildRoutes.Rebuild(true, _dbhelper);
                return("Success - post updated");
            }
            else
            {
                var s = "Error";
                foreach (ValidationFailure f in results.Errors)
                {
                    s += f.ErrorMessage;
                }
                return(s);
            }
        }
Exemplo n.º 12
0
 public WritaUser GetUserByEmail(WritaUser u)
 {
     return(database.GetCollection <WritaUser>("Users").AsQueryable().Where(w => w.EmailAddress == u.EmailAddress).SingleOrDefault());
 }
Exemplo n.º 13
0
 public WritaUser CreateUser(WritaUser u)
 {
     u.Id = System.Guid.NewGuid().ToString();
     database.GetCollection <WritaUser>("Users").Save(u);
     return(u);
 }
Exemplo n.º 14
0
 public WritaUser LogonUser(WritaUser u)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 15
0
 public WritaUser GetUserById(WritaUser u)
 {
     return(database.GetCollection <WritaUser>("Users").AsQueryable().Where(w => w.Id == u.Id).SingleOrDefault());
 }
Exemplo n.º 16
0
 public void DeleteUser(WritaUser u)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 17
0
        public ActionResult Register(string password, string username, string email, string subscribetonews)
        {
            var newEncpassword = BCrypt.Net.BCrypt.HashPassword(password, 13);

            bool subscribe = false;

            if (subscribetonews == "on")
            {
                subscribe = true;
                // this subscribes the new user to the write newsletter by pinging the writa.org API.
                try
                {
                    var client  = new RestClient("http://writa.org");
                    var request = new RestRequest("api/notify/subscribe", Method.GET);
                    request.AddParameter("email", email);
                    request.AddParameter("name", username);
                    IRestResponse response = client.Execute(request);
                    var           content  = response.Content; // raw content as string
                }
                catch { }
            }

            var ux = _dbhelper.GetUserByEmail(new WritaUser()
            {
                EmailAddress = email
            });

            if (ux == null)
            {
                WritaUser newUser = new WritaUser()
                {
                    EmailAddress          = email,
                    DateRegistered        = DateTime.Now,
                    DateLastLogin         = DateTime.Now,
                    UserFullName          = username,
                    UserPasswordEncrypted = newEncpassword,
                    UserIpAddress         = Request.ServerVariables["REMOTE_ADDR"]
                };

                WritaUser u = _dbhelper.CreateUser(newUser);

                foreach (WritaPost w in _dbhelper.GetAllPosts())
                {
                    w.PostAuthorID           = u.Id;
                    w.PostLastEditedAuthorID = u.Id;
                    w.PostLastEditedAuthor   = u.UserFullName;
                    w.PostAuthor             = u.UserFullName;
                    _dbhelper.UpdatePost(w);
                }

                //send registration email?
                //var fullurl = this.Url.Action("ValidateAccount", "Account", null, this.Request.Url.Scheme);

                //var template = System.IO.File.ReadAllText(Server.MapPath("~/App_Data/UserActivationTemplate.txt"));
                //template = template.Replace("{activationurl}", fullurl + "?key=" + u.Id + "&eml=" + u.EmailAddress);
                //NotificationEmailhelper.SendUserActivationEmail(u.Id, u.EmailAddress, template);
                //

                FormsAuthentication.RedirectFromLoginPage(u.Id, false);
            }
            else
            {
                ViewBag.RegisterError = "An account already exists";
            }


            return(View("Index"));
        }
Exemplo n.º 18
0
        public WritaUser GetUserById(WritaUser u)
        {
            var db = new WritaBlogContext();

            return(db.WritaUsers.AsQueryable().Where(w => w.Id == u.Id).SingleOrDefault());
        }