Пример #1
0
    public static string RateLink(int LinkRef, int rating)
    {
        CuplexLib.User user = HttpContext.Current.Session["User"] as CuplexLib.User;
        if (user == null || rating < 1 || rating > 5)
        {
            return("");
        }

        using (CLinq.DataContext db = CLinq.DataContext.Create())
        {
            if (!db.UserToLinks.Where(utl => utl.LinkRef == LinkRef && utl.UserRef == user.UserRef).Any() && db.Links.Where(l => l.LinkRef == LinkRef).Any())
            {
                CLinq.UserToLink userToLink = new CuplexLib.Linq.UserToLink();
                userToLink.UserRef = user.UserRef;
                userToLink.LinkRef = LinkRef;
                userToLink.Rating  = rating;
                db.UserToLinks.InsertOnSubmit(userToLink);
                db.SubmitChanges();

                //Recalculate rating on Link
                var linkRatingQuery =
                    from utl in db.UserToLinks
                    where utl.LinkRef == LinkRef
                    select utl.Rating;

                var linkToUpdate = db.Links.Where(l => l.LinkRef == LinkRef).Single();
                linkToUpdate.Rating = (double)linkRatingQuery.Sum() / (double)linkRatingQuery.Count();
                db.SubmitChanges();
            }
        }
        return("");
    }
Пример #2
0
    protected override void  OnPreRender(EventArgs e)
    {
        string resetIdentifyer = Request.QueryString["resetId"];

        if (resetIdentifyer != null && resetIdentifyer.Length == 64)
        {
            using (var db = CLinq.DataContext.Create())
            {
                var passwordReset = db.PasswordResets.Where(pr => pr.ResetIdentyfier == resetIdentifyer).Take(1).SingleOrDefault();
                if (passwordReset == null)
                {
                    NotAuthenticatedPanel.Visible = true;
                    Label errorMessage = new Label();
                    errorMessage.Text = "Angivet id är felaktigt!";
                    NotAuthenticatedPanel.Controls.Add(errorMessage);
                }
                else
                {
                    CuplexLib.User user = CuplexLib.User.GetOne(passwordReset.UserRef);
                    AccessControl.CreateUserSession(user.UserName);
                    db.PasswordResets.DeleteBatch(pr => pr.UserRef == user.UserRef);
                    AuthenticatedPanel.Visible = true;
                }
            }
        }
    }
Пример #3
0
    private void saveUploadFile()
    {
        CuplexLib.User user = Session["User"] as CuplexLib.User;
        if (user == null)
        {
            return;
        }

        string fileName = cms.Current.LocalFilePath + "Upload\\" + user.UserRef + ".json";

        try
        {
            FileStream fs        = File.Create(fileName);
            byte[]     buffer    = new byte[102400];
            int        bytesRead = 0;

            do
            {
                bytesRead = FileUploadControl.FileContent.Read(buffer, 0, buffer.Length);
                fs.Write(buffer, 0, bytesRead);
            }while (bytesRead > 0);

            fs.Close();
        }
        catch (Exception ex)
        {
            EventLog.SaveToEventLog(ex.Message, EventLogType.Error, user.UserRef);
        }
    }
Пример #4
0
 protected void UploadButton_Clicked(object sender, EventArgs e)
 {
     CuplexLib.User user = Session["User"] as CuplexLib.User;
     if (FileUploadControl.HasFile)
     {
         try
         {
             if (FileUploadControl.PostedFile.ContentLength > MAX_UPLOAD_SIZE)
             {
                 ShowModalMessage(Utils.GetResourceText("ToLargeUploadFileText"));
                 return;
             }
             saveUploadFile();
             Bookmark.ParseJsonBookmarkFile(user.UserRef, cms.Current.LocalFilePath + "Upload\\" + user.UserRef + ".json");
         }
         catch (Exception ex)
         {
             EventLog.SaveToEventLog(ex.Message, EventLogType.Error, user.UserRef);
         }
     }
     else
     {
         ShowModalMessage(Utils.GetResourceText("NoFileSelectedText"));
     }
 }
Пример #5
0
    public void LoadDataFromSearch(string searchText, List <CLinq.Link> linkList, CLinq.DataContext db)
    {
        CuplexLib.User user = HttpContext.Current.Session["User"] as CuplexLib.User;

        foreach (var lnk in linkList)
        {
            LinkDataItem linkDataItem = new LinkDataItem();
            linkDataItem.LinkRef  = lnk.LinkRef;
            linkDataItem.Category = lnk.Category.CategoryName;
            linkDataItem.Clicks   = lnk.Clicks;
            linkDataItem.LinkName = lnk.LinkName;
            linkDataItem.LinkUrl  = lnk.LinkUrl;
            linkDataItem.Rating   = lnk.Rating;
            if (lnk.UserRef != null)
            {
                linkDataItem.UserName = lnk.User.UserName;
            }

            if (user != null)
            {
                linkDataItem.HasVoted = db.UserToLinks.Where(utl => utl.LinkRef == lnk.LinkRef && utl.UserRef == user.UserRef).Any();
            }

            linkDataItem.NumberOfComments = lnk.Comments.Count;

            linkDataItemList.Add(linkDataItem);
        }
        IsDisplayingSearchResult = true;
        SearchString             = searchText;
    }
Пример #6
0
 protected void Page_Load(object sender, EventArgs e)
 {
     CuplexLib.User user = Session["User"] as CuplexLib.User;
     if (user == null || !user.IsAdmin)
     {
         Server.Transfer("StartPage.aspx");
     }
 }
Пример #7
0
 public string VoteOnPoll(int pollOptionRef)
 {
     CuplexLib.User user = HttpContext.Current.Session["User"] as CuplexLib.User;
     if (user == null)
     {
         return("0");
     }
     return(CuplexLib.PollHandler.VoteOnPoll(pollOptionRef, user));
 }
Пример #8
0
    protected void CreateUserButton_Clicked(object sender, EventArgs e)
    {
        string userName     = UserNameTextBox.Text;
        string password     = PasswordTextBox.Text;
        string emailAddress = EmailAddressTextBox.Text;

        if (userName == "" || password == "" || emailAddress == "")
        {
            return;
        }

        //Check if user exists
        if (CuplexLib.User.UserNameExists(userName))
        {
            ShowModalMessage(Utils.GetResourceText("RegisterUserUsernameTaken"));
            return;
        }
        else if (!Utils.ValidateEmail(emailAddress))
        {
            ShowModalMessage(Utils.GetResourceText("RegisterUserIncorrectEmailAddress"));
            return;
        }
        else if (password != PasswordConfirmTextBox.Text)
        {
            ShowModalMessage(Utils.GetResourceText("RegisterUserPasswordMissmatch"));
            return;
        }

        //Verify password strength
        PasswordVerifier passwordVerifier = new PasswordVerifier();

        PasswordVerifier.PasswordVerifierResult passwordVerificationResult = passwordVerifier.VerifyPassword(password);

        if (passwordVerificationResult != PasswordVerifier.PasswordVerifierResult.PasswordIsOk)
        {
            string errorMessage = "<b>" + Utils.GetResourceText(Enum.GetName(typeof(PasswordVerifier.PasswordVerifierResult), passwordVerificationResult)) + "</b>";
            errorMessage += "<BR/>" + string.Format(Utils.GetResourceText("PasswordRules"), passwordVerifier.MinimumPasswordLength, passwordVerifier.MinimumPasswordCapitalLetters, passwordVerifier.MinimumPasswordDigits);
            ShowModalMessage(errorMessage);
            return;
        }

        //Verify UserName
        if (!UserNameVerifier.VerifyUserName(userName))
        {
            ShowModalMessage(Utils.GetResourceText("IncorrectUserName"));
            return;
        }

        CuplexLib.User createdUser = CuplexLib.User.CreateUser(userName, password, emailAddress);
        if (createdUser != null)
        {
            AccessControl.CreateUserSession(createdUser.UserName);
            Response.Redirect(cms.Current.GetRootPath);
        }
    }
Пример #9
0
    protected void Page_Load(object sender, EventArgs e)
    {
        CuplexLib.User user = Session["User"] as CuplexLib.User;

        if (user == null || !user.IsAdmin)
        {
            Response.Redirect(cms.Current.GetRootPath, true);
            return;
        }

        SaveButton.Text = Utils.GetResourceText("SaveButton");
        RenderSettingsTable();
    }
Пример #10
0
    protected override void OnPreRender(EventArgs e)
    {
        CuplexLib.User user = Session["User"] as CuplexLib.User;
        logoutLink.HRef      = cms.Current.GetRootPath + "logout";
        accountSettings.HRef = cms.Current.GetRootPath + "user/settings";
        suggestionLink.HRef  = cms.Current.GetRootPath + "link";
        adminLink.HRef       = cms.Current.GetRootPath + "admin";
        homeLink.HRef        = cms.Current.GetRootPath;

        if (user != null && user.IsAdmin)
        {
            AdminLinkPlaceholder.Visible = true;
        }

        base.OnPreRender(e);
    }
Пример #11
0
    protected void UpdateUserSettingsButton_Clicked(object sender, EventArgs e)
    {
        CuplexLib.User user     = Session["User"] as CuplexLib.User;
        string         password = null;

        if (UpdatePasswordCheckBox.Checked)
        {
            password = PasswordTextBox.Text;
        }

        if (user == null || !ValidateBeforeSave())
        {
            return;
        }

        Session["User"] = CuplexLib.User.UpdateUser(user.UserRef, password, Utils.TruncateString(EmailAddressTextBox.Text, 100));
    }
Пример #12
0
    protected void PostCommentButton_Clicked(object sender, EventArgs e)
    {
        CuplexLib.User user = Session["User"] as CuplexLib.User;
        if (user == null || LinkRef == 0 || CommentTextBox.Text.Length == 0)
        {
            return;
        }

        Comment comment = new Comment();

        comment.CommentDate = DateTime.Now;
        comment.CommentText = Utils.TruncateString(CommentTextBox.Text, 5000);
        comment.LinkRef     = this.LinkRef;
        comment.UserRef     = user.UserRef;

        comment.Save();
        CommentTextBox.Text = "";
    }
Пример #13
0
    protected override void OnPreRender(EventArgs e)
    {
        CuplexLib.User user = Session["User"] as CuplexLib.User;
        if (user == null || !user.IsAdmin)
        {
            return;
        }

        AdminPagePanel.Visible = true;
        registerScripts();
        if (!IsPostBack)
        {
            FromDateTextBox.Text  = DateHandler.ToDateString(DateTime.Today.AddDays(-3));
            UntilDateTextBox.Text = DateHandler.ToDateString(DateTime.Today);
            loadDataList();
        }

        base.OnPreRender(e);
    }
Пример #14
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["User"] is CuplexLib.User)
        {
            NotLoggedInMainWrapper.Visible = false;
            LoggedInMainWrapper.Visible    = true;

            CuplexLib.User user = (CuplexLib.User)Session["User"];
            loggedInUserBox.InnerHtml = "<span>Välkommen till Cuplex</span><span>" + user.UserName + "</span>";
        }
        else
        {
            NotLoggedInMainWrapper.Visible = true;
            LoggedInMainWrapper.Visible    = false;

            string script = "document.getElementById('" + this.PasswordTextBox.ClientID + "').value = '123456789';";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "LoginScript", script, true);
        }

        createUserLink.HRef = cms.Current.GetRootPath + "user/createuser";
    }
Пример #15
0
    protected void SuggestLinkButton_Clicked(object sender, EventArgs e)
    {
        CuplexLib.User user = Session["User"] as CuplexLib.User;
        if (user != null && ValidateBeforeSave())
        {
            LinkSuggestion link = new LinkSuggestion();
            link.UserRef            = user.UserRef;
            link.CategoryRef        = int.Parse(CategoryDropdownList.SelectedValue);
            link.Description        = Utils.TruncateString(DescriptionTextBox.Text, 250);
            link.LinkUrl            = Utils.TruncateString(UrlTextBox.Text, 500);
            link.LinkSuggestionDate = DateTime.Now;
            link.Save();

            DescriptionTextBox.Text = "";
            UrlTextBox.Text         = "";
            Label messageLabel = new Label();
            messageLabel.Text = "Länken är nu postad";
            LinkSuggestMessagePanel.Visible = true;
            LinkSuggestMessagePanel.Controls.Add(messageLabel);
        }
    }
Пример #16
0
    public void LoadData(DateTime linkDate)
    {
        CuplexLib.User user = HttpContext.Current.Session["User"] as CuplexLib.User;
        LinkDataListDate = linkDate;
        using (CLinq.DataContext db = CLinq.DataContext.Create())
        {
            var linkQuery =
                from lnk in db.Links
                where lnk.LinkDate.Date == linkDate
                orderby lnk.LinkDate descending
                select lnk;

            List <CLinq.Link> linkList = linkQuery.ToList();
            foreach (var lnk in linkList)
            {
                LinkDataItem linkDataItem = new LinkDataItem();
                linkDataItem.LinkRef  = lnk.LinkRef;
                linkDataItem.Category = lnk.Category.CategoryName;
                linkDataItem.Clicks   = lnk.Clicks;
                linkDataItem.LinkName = lnk.LinkName;
                linkDataItem.LinkUrl  = lnk.LinkUrl;
                linkDataItem.Rating   = lnk.Rating;
                if (lnk.UserRef != null)
                {
                    linkDataItem.UserName = lnk.User.UserName;
                }

                if (user != null)
                {
                    linkDataItem.HasVoted = db.UserToLinks.Where(utl => utl.LinkRef == lnk.LinkRef && utl.UserRef == user.UserRef).Any();
                }

                linkDataItem.NumberOfComments = lnk.Comments.Count;

                linkDataItemList.Add(linkDataItem);
            }
        }
    }
Пример #17
0
    protected void AddLinkButton_Clicked(object sender, EventArgs e)
    {
        CuplexLib.User user = Session["User"] as CuplexLib.User;
        LinkDateTextBox.Text = DateHandler.ToDateString(DateTime.Today);
        LinkTimeTextBox.Text = DateHandler.ToTimeString(DateTime.Now);
        LinkCategoryDropdownList.DataValueField = "CategoryRef";
        LinkCategoryDropdownList.DataTextField  = "CategoryName";
        LinkCategoryDropdownList.DataSource     = Category.GetCategoryList();
        LinkCategoryDropdownList.DataBind();

        LinkUserDropDownList.Items.Clear();
        LinkUserDropDownList.Items.Add(new ListItem("null", "0"));
        LinkUserDropDownList.Items.Add(new ListItem(user.UserName, user.UserRef.ToString()));
        LinkUserDropDownList.SelectedIndex = 1;

        LinkNameTextBox.Text   = "";
        LinkUrlTextBox.Text    = "";
        LinkClicksTextBox.Text = "0";
        LinkRatingTextBox.Text = "0";

        this.ViewState["EditLinkRef"] = 0;
        EditLinkPanel.Visible         = true;
        base.ShowModalBackground();
    }
Пример #18
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["User"] == null)
            {
                Response.Redirect(cms.Current.GetRootPath);
            }
            else
            {
                CuplexLib.User user = (CuplexLib.User)Session["User"];
                EmailAddressTextBox.Text = user.EmailAddress;
            }
        }

        string script = @"
        function confirmPassword() {
            var password1 = document.getElementById('" + PasswordTextBox.ClientID + @"').value;
            var password2 = document.getElementById('" + PasswordConfirmTextBox.ClientID + @"').value;
            var updatePassword =document.getElementById('" + UpdatePasswordCheckBox.ClientID + @"').checked;  
            
            if (!updatePassword) return true;

            if (password1 != password2) {
                alert('Lösenorden matchar inte!');
                return false;
            }            
            else if (password1.length < 5){
                alert('Lösenordet är inte tillräckligt långt!');
                return false;
            }
            return true;
        }";

        ScriptManager.RegisterStartupScript(this, this.GetType(), "AccountSettingsScript", script, true);
    }
Пример #19
0
    protected void EditButton_Clicked(object sender, EventArgs e)
    {
        CuplexLib.User user = Session["User"] as CuplexLib.User;
        if (SelectedView == ViewMode.LinkSuggestion)
        {
            List <int> linkSuggestionRefList = GetPostCollection("SuggestionCheckBox");
            if (linkSuggestionRefList.Count > 0)
            {
                LinkSuggestion linkSuggestion = LinkSuggestion.GetOne(linkSuggestionRefList[0]);
                if (linkSuggestion == null)
                {
                    return;
                }

                LinkSuggestionDescriptionTextBox.Text = linkSuggestion.Description;
                LinkSuggestionUrlTextBox.Text         = linkSuggestion.LinkUrl;

                LinkSuggestionCategoryDropdownList.DataValueField = "CategoryRef";
                LinkSuggestionCategoryDropdownList.DataTextField  = "CategoryName";
                LinkSuggestionCategoryDropdownList.DataSource     = Category.GetCategoryList();
                LinkSuggestionCategoryDropdownList.DataBind();

                try { LinkSuggestionCategoryDropdownList.SelectedValue = linkSuggestion.CategoryRef.ToString(); }
                catch { }

                this.ViewState["EditLinkSuggestionRef"] = linkSuggestion.LinkSuggestionRef;
                EditLinkSuggestionPanel.Visible         = true;
                base.ShowModalBackground();
            }
        }
        else if (SelectedView == ViewMode.LinkAdministration)
        {
            List <int> selectedLinkRefRefList = GetPostCollection("LinkSelectionCheckBox");
            if (selectedLinkRefRefList.Count > 0)
            {
                Link link = Link.GetOne(selectedLinkRefRefList[0]);
                if (link == null)
                {
                    return;
                }

                LinkDateTextBox.Text = DateHandler.ToDateString(link.LinkDate);
                LinkTimeTextBox.Text = DateHandler.ToTimeString(link.LinkDate);
                LinkNameTextBox.Text = link.LinkName;

                LinkCategoryDropdownList.DataValueField = "CategoryRef";
                LinkCategoryDropdownList.DataTextField  = "CategoryName";
                LinkCategoryDropdownList.DataSource     = Category.GetCategoryList();
                LinkCategoryDropdownList.DataBind();

                try { LinkCategoryDropdownList.SelectedValue = link.CategoryRef.ToString(); }
                catch { }

                LinkUserDropDownList.Items.Clear();
                LinkUserDropDownList.Items.Add(new ListItem("null", "0"));

                if (link.UserRef != user.UserRef)
                {
                    LinkUserDropDownList.Items.Add(new ListItem(user.UserName, user.UserRef.ToString()));
                }

                if (link.UserRef != null)
                {
                    LinkUserDropDownList.Items.Add(new ListItem(link.UserName, link.UserRef.Value.ToString()));
                    LinkUserDropDownList.SelectedValue = link.UserRef.Value.ToString();
                }

                LinkUrlTextBox.Text    = link.LinkUrl;
                LinkClicksTextBox.Text = link.Clicks.ToString();
                LinkRatingTextBox.Text = Math.Round(link.Rating, 2).ToString();

                this.ViewState["EditLinkRef"] = link.LinkRef;
                EditLinkPanel.Visible         = true;
                base.ShowModalBackground();
            }
        }
    }
Пример #20
0
    protected override void OnPreRender(EventArgs e)
    {
        CuplexLib.User user         = HttpContext.Current.Session["User"] as CuplexLib.User;
        Table          contentTable = new Table();

        contentTable.CellPadding = 0;
        contentTable.CellSpacing = 0;
        contentTable.CssClass    = "contentList";
        TableHeaderRow  thr = new TableHeaderRow();
        TableHeaderCell thc = new TableHeaderCell();

        thc.ColumnSpan = 3;
        if (IsDisplayingSearchResult)
        {
            thc.Text = "Sökresultat för: " + SearchString;
        }
        else
        {
            thc.Text = Utils.GetResourceText("WeekDay" + (int)LinkDataListDate.DayOfWeek) + " " + DateHandler.ToDateString(LinkDataListDate);
        }
        thr.Cells.Add(thc);
        contentTable.Rows.Add(thr);
        int    rowCnt  = 0;
        string baseUrl = cms.Current.GetRootPath;

        foreach (LinkDataItem linkDataItem in linkDataItemList)
        {
            TableRow  tr = new TableRow();
            TableCell td = new TableCell();

            //Column1
            HtmlGenericControl theLink = new HtmlGenericControl("a");
            theLink.InnerHtml = HttpContext.Current.Server.HtmlEncode(linkDataItem.LinkName);
            theLink.Attributes.Add("href", baseUrl + "go/" + linkDataItem.LinkRef);
            theLink.Attributes.Add("target", "_blank");


            Table innerTable = new Table();
            innerTable.CellSpacing = 0;
            innerTable.CellPadding = 0;

            TableRow  innerTableRow  = new TableRow();
            TableCell innerTableCell = new TableCell();
            innerTableCell.ColumnSpan = 3;

            innerTableCell.CssClass = "link";
            innerTableCell.Controls.Add(theLink);
            innerTableRow.Cells.Add(innerTableCell);
            innerTable.Rows.Add(innerTableRow);

            innerTableRow           = new TableRow();
            innerTableCell          = new TableCell();
            innerTableCell.CssClass = "innerTableCell";
            innerTableCell.Text     = "Kategori: " + linkDataItem.Category;
            innerTableRow.Cells.Add(innerTableCell);

            innerTableCell          = new TableCell();
            innerTableCell.CssClass = "innerTableCell";
            innerTableCell.Text     = "Klick: " + linkDataItem.Clicks;
            innerTableRow.Cells.Add(innerTableCell);

            innerTableCell          = new TableCell();
            innerTableCell.CssClass = "innerTableCell";
            innerTableCell.Text     = "Tipsare: " + linkDataItem.UserName;
            innerTableRow.Cells.Add(innerTableCell);

            TableRow  subTableRow  = new TableRow();
            TableCell subTableCell = new TableCell();
            Table     subTable     = new Table();
            subTable.CellPadding = 0;
            subTable.CellSpacing = 0;
            subTable.Style.Add(HtmlTextWriterStyle.Margin, "0");
            subTable.Rows.Add(innerTableRow);

            subTableCell.Controls.Add(subTable);
            subTableRow.Cells.Add(subTableCell);


            innerTable.Rows.Add(subTableRow);

            td.Controls.Add(innerTable);
            tr.Cells.Add(td);

            //Column2
            td = new TableCell();
            //td.Text = "Betyg här!";
            StarVotingControl votingControl = new StarVotingControl();
            votingControl.LinkRef  = linkDataItem.LinkRef;
            votingControl.Rating   = linkDataItem.Rating;
            votingControl.HasVoted = linkDataItem.HasVoted;
            if (user != null)
            {
                votingControl.UserRef = user.UserRef;
            }
            td.Controls.Add(votingControl);

            td.CssClass = "votingTd";
            tr.Cells.Add(td);

            //Column3
            td          = new TableCell();
            td.CssClass = "rightColumn commentTd";
            HtmlGenericControl commentLink = new HtmlGenericControl("a");
            commentLink.Attributes.Add("class", "commentLink");
            commentLink.Attributes.Add("href", "#");
            if (user != null)
            {
                commentLink.Attributes.Add("onclick", "javascript:ShowPopup('" + cms.Current.GetRootPath + "Comment.aspx?linkId=" + linkDataItem.LinkRef + "',530,440);return false;");
            }
            else
            {
                commentLink.Attributes.Add("onclick", "javascript:ShowPopup('" + cms.Current.GetRootPath + "Comment.aspx?linkId=" + linkDataItem.LinkRef + "',530,315);return false;");
            }
            commentLink.InnerHtml = linkDataItem.NumberOfComments.ToString() + " inlägg";
            td.Controls.Add(commentLink);

            tr.Cells.Add(td);

            if (rowCnt % 2 == 1)
            {
                tr.CssClass = "listRow";
            }
            else
            {
                tr.CssClass = "listRowAlt";
            }

            rowCnt++;
            contentTable.Rows.Add(tr);
        }

        this.CssClass = "contentWrapper dropShadowSoft";
        this.Controls.Add(contentTable);
        base.OnPreRender(e);
    }