Example #1
0
 public static bool UserNameExists(string userName)
 {
     using (CuplexLib.Linq.DataContext db = CuplexLib.Linq.DataContext.Create())
     {
         return(db.Users.Any(u => u.UserName == userName));
     }
 }
Example #2
0
        public static User CreateUser(string userName, string password, string emailAddress)
        {
            User user = null;

            using (CuplexLib.Linq.DataContext db = CuplexLib.Linq.DataContext.Create())
            {
                if (db.Users.Any(u => u.UserName == userName))
                {
                    return(null);
                }

                CuplexLib.Linq.User dbUser = new CuplexLib.Linq.User();
                dbUser.UserName     = userName;
                dbUser.PasswordHash = Utils.GetMd5Hash(password);
                dbUser.EmailAddress = emailAddress;

                db.Users.InsertOnSubmit(dbUser);
                db.SubmitChanges();

                user = new User();
                user.EmailAddress = emailAddress;
                user.UserName     = userName;
                user.UserRef      = dbUser.UserRef;
                user.PasswordHash = dbUser.PasswordHash;
            }

            return(user);
        }
Example #3
0
        public void save()
        {
            if (UserRef > 0)
            {
                using (CuplexLib.Linq.DataContext db = CuplexLib.Linq.DataContext.Create())
                {
                    CuplexLib.Linq.User dbUser = db.Users.Where(u => u.UserRef == UserRef).SingleOrDefault();
                    if (dbUser == null)
                    {
                        return;
                    }

                    dbUser.LastLogin    = LastLogin;
                    dbUser.EmailAddress = EmailAddress;

                    db.SubmitChanges();
                }
            }
        }
Example #4
0
        public static User UpdateUser(int userRef, string password, string emailAddress)
        {
            using (CuplexLib.Linq.DataContext db = CuplexLib.Linq.DataContext.Create())
            {
                CuplexLib.Linq.User user = db.Users.Where(u => u.UserRef == userRef).SingleOrDefault();
                if (user == null)
                {
                    return(null);
                }
                if (password != null)
                {
                    user.PasswordHash = Utils.GetMd5Hash(password);
                }
                user.EmailAddress = emailAddress;
                db.SubmitChanges();

                return(GetOne(userRef));
            }
        }
Example #5
0
        public static User GetOneByUserName(string userName)
        {
            User usr = null;

            using (CuplexLib.Linq.DataContext db = CuplexLib.Linq.DataContext.Create())
            {
                CuplexLib.Linq.User user = db.Users.Where(u => u.UserName == userName).SingleOrDefault();
                if (user != null)
                {
                    usr              = new User();
                    usr.UserRef      = user.UserRef;
                    usr.UserName     = user.UserName;
                    usr.EmailAddress = user.EmailAddress;
                    usr.IsAdmin      = user.IsAdmin;
                    usr.LastLogin    = user.LastLogin;
                }
            }

            return(usr);
        }
Example #6
0
        public static UserAuthenticateResponce AuthenticateUser(string userName, string password)
        {
            using (CuplexLib.Linq.DataContext db = CuplexLib.Linq.DataContext.Create())
            {
                var user = db.Users.Where(u => u.UserName == userName).SingleOrDefault();

                if (user == null)
                {
                    return(UserAuthenticateResponce.UnknownUser);
                }

                if (user.PasswordHash == Utils.GetMd5Hash(password))
                {
                    return(UserAuthenticateResponce.PasswordCorrect);
                }
                else
                {
                    return(UserAuthenticateResponce.PasswordIncorrect);
                }
            }
        }
Example #7
0
        void context_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication app = sender as HttpApplication;

            try
            {
                string path = app.Request.Url.LocalPath.Substring(app.Request.ApplicationPath.Length);
                path = this.ensureBeginsWithSlash(path);
                Url requestUrl = new Url(path, app.Request.QueryString);


                //Debug Code -------------------
                //app.Response.Write("Nu körs en request, sökväg:" + app.Request.Url.AbsolutePath);
                //CuplexLib.EventLog.SaveToEventLog(app.Request.Url.AbsoluteUri, CuplexLib.EventLogType.Information, null);
                //CuplexLib.EventLog.SaveToEventLog("sökväg->" + path, EventLogType.Information, null);
                //Debug Code -------------------


                if (requestUrl.MatchPath("/go/<int>"))
                {
                    int    linkRef;
                    int    length     = Math.Min(64, path.Length);
                    string strLinkRef = path.Substring(4, length - 4);
                    if (int.TryParse(strLinkRef, out linkRef))
                    {
                        try
                        {
                            string redirectUrl = cms.Current.GetRootPath;
                            using (CuplexLib.Linq.DataContext db = CuplexLib.Linq.DataContext.Create())
                            {
                                var link = db.Links.SingleOrDefault(l => l.LinkRef == linkRef);
                                if (link != null)
                                {
                                    redirectUrl = link.LinkUrl;
                                    link.Clicks++;
                                    db.SubmitChanges();
                                }
                            }
                            app.Response.Redirect(redirectUrl);
                        }
                        catch (Exception ex)
                        {
                            string errorMessage = ex.Message;
                        }
                    }
                }
                else if (requestUrl.MatchPath("/page/<int>"))
                {
                    int    pageId;
                    int    length    = Math.Min(64, path.Length);
                    string strPageId = path.Substring(6, length - 6);
                    if (int.TryParse(strPageId, out pageId))
                    {
                        try
                        {
                            string pathToUse = this.removeEndingSlash(app.Request.ApplicationPath) + "/StartPage.aspx?pageId=" + pageId;
                            app.Context.RewritePath(pathToUse);
                        }
                        catch (Exception ex)
                        {
                            string errorMessage = ex.Message;
                            EventLog.SaveToEventLog("'/page/<int>' " + errorMessage, EventLogType.Error, null);
                        }
                    }
                }
                else if (requestUrl.MatchPath("/page/<*>"))
                {
                    try
                    {
                        string pathToUse = this.removeEndingSlash(app.Request.ApplicationPath) + requestUrl.Path.Replace("/page", "");
                        app.Context.RewritePath(pathToUse);
                    }
                    catch (Exception ex)
                    {
                        string errorMessage = ex.Message;
                        EventLog.SaveToEventLog("/page/<*>' " + errorMessage, EventLogType.Error, null);
                    }
                }
                else if (requestUrl.MatchPath("/user/login"))
                {
                    app.Response.Redirect(Current.GetRootPath + "ManageUser.aspx?action=login");
                }
                else if (requestUrl.MatchPath("/user/createuser"))
                {
                    app.Response.Redirect(Current.GetRootPath + "ManageUser.aspx?action=createuser");
                }
                else if (requestUrl.MatchPath("/logout"))
                {
                    app.Response.Redirect(Current.GetRootPath + "StartPage.aspx?action=logout");
                }
                else if (requestUrl.MatchPath("/link"))
                {
                    app.Response.Redirect(Current.GetRootPath + "SuggestLink.aspx");
                }
                else if (requestUrl.MatchPath("/user/settings"))
                {
                    app.Response.Redirect(Current.GetRootPath + "AccountSettings.aspx");
                    //app.Context.RewritePath(app.Request.ApplicationPath + "/AccountSettings.aspx");
                }
                else if (requestUrl.MatchPath("/admin"))
                {
                    //app.Context.RewritePath(removeEndingSlash(app.Request.ApplicationPath) + "/AdminPage.aspx");
                    app.Response.Redirect(Current.GetRootPath + "AdminPage.aspx");
                }
                else if (requestUrl.MatchPath("/settings"))
                {
                    //app.Response.Redirect(Current.GetRootPath + "Settings.aspx");
                    string pathToUse;
                    if (path == "/settings/")
                    {
                        pathToUse = this.removeEndingSlash(app.Request.ApplicationPath) + "/Settings.aspx";
                    }
                    else
                    {
                        pathToUse = this.removeEndingSlash(app.Request.ApplicationPath) + requestUrl.Path.Replace("/settings", "");
                    }

                    app.Context.RewritePath(pathToUse);
                }
                else if (requestUrl.MatchPath("/search"))
                {
                    string pathToUse;
                    if (path == "/search/")
                    {
                        pathToUse = this.removeEndingSlash(app.Request.ApplicationPath) + "/StartPage.aspx";
                    }
                    else
                    {
                        pathToUse = this.removeEndingSlash(app.Request.ApplicationPath) + requestUrl.Path.Replace("/search", "");
                    }

                    app.Context.RewritePath(pathToUse);
                }
                else if (requestUrl.MatchPath("/randimg"))
                {
                    string pathToUse;
                    if (path == "/randimg/")
                    {
                        pathToUse = this.removeEndingSlash(app.Request.ApplicationPath) + "/RandomImage.aspx";
                    }
                    else
                    {
                        if (requestUrl.Path.Substring(9).Contains('/'))
                        {
                            pathToUse = this.removeEndingSlash(app.Request.ApplicationPath) + "/" + requestUrl.Path.Substring(9);
                        }
                        else if (requestUrl.Path == "/randimg/RandomImage.aspx")
                        {
                            pathToUse = this.removeEndingSlash(app.Request.ApplicationPath) + "/RandomImage.aspx";
                        }
                        else
                        {
                            pathToUse = this.removeEndingSlash(app.Request.ApplicationPath) + "/RandomImage.aspx?img=" + requestUrl.Path.Substring(9);
                        }
                    }
                    //pathToUse = removeEndingSlash(app.Request.ApplicationPath) +"/RandomImage.aspx?img=" + requestUrl.Path.Replace("/randimg", "");

                    app.Context.RewritePath(pathToUse);
                }
                else if (requestUrl.MatchPath("/about"))
                {
                    string pathToUse;
                    if (path == "/about/")
                    {
                        pathToUse = this.removeEndingSlash(app.Request.ApplicationPath) + "/AboutPage.aspx";
                    }
                    else
                    {
                        pathToUse = this.removeEndingSlash(app.Request.ApplicationPath) + requestUrl.Path.Replace("/about", "");
                    }

                    app.Context.RewritePath(pathToUse);
                }
                //else if (requestUrl.MatchPath("/utils"))
                //{
                //    string pathToUse;
                //    if (path == "/utils/")
                //        pathToUse = removeEndingSlash(app.Request.ApplicationPath) + "/Utils.aspx";
                //    else
                //        pathToUse = removeEndingSlash(app.Request.ApplicationPath) + requestUrl.Path.Replace("/utils", "");

                //    app.Context.RewritePath(pathToUse);
                //}
            }
            catch (Exception ex) { app.Response.Write(ex.Message); }
        }