Fossil SCM

If the user is not logged in, prompt them to do so before continuing to the forum entry pages.

drh 2018-07-31 01:03 forum-v2
Commit 009ca1f74e48b232cd7ac5762ab4b45494d8916a416f7d6bc3193ce72595be6d
2 files changed +81 -8 +4 -3
+81 -8
--- src/forum.c
+++ src/forum.c
@@ -631,10 +631,79 @@
631631
@ rows="25" wrap="virtual">%h(zContent)</textarea><br>
632632
}
633633
634634
/*
635635
** WEBPAGE: forumnew
636
+** WEBPAGE: forumedit
637
+**
638
+** Start a new thread on the forum or reply to an existing thread.
639
+** But first prompt to see if the user would like to log in.
640
+*/
641
+void forum_page_init(void){
642
+ int isEdit;
643
+ char *zGoto;
644
+ login_check_credentials();
645
+ if( !g.perm.WrForum ){
646
+ login_needed(g.anon.WrForum);
647
+ return;
648
+ }
649
+ if( sqlite3_strglob("*edit*", g.zPath)==0 ){
650
+ zGoto = mprintf("%R/forume2?fpid=%S",PD("fpid",""));
651
+ isEdit = 1;
652
+ }else{
653
+ zGoto = mprintf("%R/forume1");
654
+ isEdit = 0;
655
+ }
656
+ if( login_is_individual() ){
657
+ if( isEdit ){
658
+ forumedit_page();
659
+ }else{
660
+ forumnew_page();
661
+ }
662
+ return;
663
+ }
664
+ style_header("%h As Anonymous?", isEdit ? "Reply" : "Post");
665
+ @ <p>You are not logged in.
666
+ @ <p><table border="0" cellpadding="10">
667
+ @ <tr><td>
668
+ @ <form action="%s(zGoto)" method="POST">
669
+ @ <input type="submit" value="Remain Anonymous">
670
+ @ </form>
671
+ @ <td>Post to the forum anonymously
672
+ if( login_self_register_available(0) ){
673
+ @ <tr><td>
674
+ @ <form action="%R/register" method="POST">
675
+ @ <input type="hidden" name="g" value="%s(zGoto)">
676
+ @ <input type="submit" value="Create An Account">
677
+ @ </form>
678
+ @ <td>Create a new account and post using that new account
679
+ }
680
+ @ <tr><td>
681
+ @ <form action="%R/login" method="POST">
682
+ @ <input type="hidden" name="g" value="%s(zGoto)">
683
+ @ <input type="hidden" name="noanon" value="1">
684
+ @ <input type="submit" value="Login">
685
+ @ </form>
686
+ @ <td>Log into an existing account
687
+ @ </table>
688
+ style_footer();
689
+ fossil_free(zGoto);
690
+}
691
+
692
+/*
693
+** Write the "From: USER" line on the webpage.
694
+*/
695
+static void forum_from_line(void){
696
+ if( login_is_nobody() ){
697
+ @ From: anonymous<br>
698
+ }else{
699
+ @ From: %h(login_name())<br>
700
+ }
701
+}
702
+
703
+/*
704
+** WEBPAGE: forume1
636705
**
637706
** Start a new forum thread.
638707
*/
639708
void forumnew_page(void){
640709
const char *zTitle = PDT("title","");
@@ -651,11 +720,13 @@
651720
if( P("preview") ){
652721
@ <h1>Preview:</h1>
653722
forum_render(zTitle, zMimetype, zContent, "forumEdit");
654723
}
655724
style_header("New Forum Thread");
656
- @ <form action="%R/%s(g.zPath)" method="POST">
725
+ @ <form action="%R/forume1" method="POST">
726
+ @ <h1>New Message:</h1>
727
+ forum_from_line();
657728
forum_entry_widget(zTitle, zMimetype, zContent);
658729
@ <input type="submit" name="preview" value="Preview">
659730
if( P("preview") ){
660731
@ <input type="submit" name="submit" value="Submit">
661732
}else{
@@ -675,16 +746,16 @@
675746
@ </form>
676747
style_footer();
677748
}
678749
679750
/*
680
-** WEBPAGE: forumedit
751
+** WEBPAGE: forume2
681752
**
682753
** Edit an existing forum message.
683754
** Query parameters:
684755
**
685
-** name=X Hash of the post to be editted. REQUIRED
756
+** fpid=X Hash of the post to be editted. REQUIRED
686757
*/
687758
void forumedit_page(void){
688759
int fpid;
689760
Manifest *pPost;
690761
const char *zMimetype = 0;
@@ -741,11 +812,11 @@
741812
@ <h1>Original Post:</h1>
742813
forum_render(pPost->zThreadTitle, pPost->zMimetype, pPost->zWiki,
743814
"forumEdit");
744815
@ <h1>Change Into:</h1>
745816
forum_render(zTitle, zMimetype, zContent,"forumEdit");
746
- @ <form action="%R/forumedit" method="POST">
817
+ @ <form action="%R/forume2" method="POST">
747818
@ <input type="hidden" name="fpid" value="%h(P("fpid"))">
748819
@ <input type="hidden" name="nullout" value="1">
749820
@ <input type="hidden" name="mimetype" value="%h(zMimetype)">
750821
@ <input type="hidden" name="content" value="%h(zContent)">
751822
if( zTitle ){
@@ -767,14 +838,15 @@
767838
"forumEdit");
768839
if( P("preview") ){
769840
@ <h1>Preview Of Editted Post:</h1>
770841
forum_render(zTitle, zMimetype, zContent,"forumEdit");
771842
}
772
- @ <h1>Enter A Reply:</h1>
773
- @ <form action="%R/forumedit" method="POST">
843
+ @ <h1>Revised Message:</h1>
844
+ @ <form action="%R/forume2" method="POST">
774845
@ <input type="hidden" name="fpid" value="%h(P("fpid"))">
775846
@ <input type="hidden" name="edit" value="1">
847
+ forum_from_line();
776848
forum_entry_widget(zTitle, zMimetype, zContent);
777849
}else{
778850
/* Reply */
779851
zMimetype = PD("mimetype","text/x-fossil-wiki");
780852
zContent = PDT("content","");
@@ -783,14 +855,15 @@
783855
forum_render(0, pPost->zMimetype, pPost->zWiki, "forumEdit");
784856
if( P("preview") ){
785857
@ <h1>Preview:</h1>
786858
forum_render(0, zMimetype,zContent, "forumEdit");
787859
}
788
- @ <h1>Enter A Reply:</h1>
789
- @ <form action="%R/forumedit" method="POST">
860
+ @ <h1>Enter Reply:</h1>
861
+ @ <form action="%R/forume2" method="POST">
790862
@ <input type="hidden" name="fpid" value="%h(P("fpid"))">
791863
@ <input type="hidden" name="reply" value="1">
864
+ forum_from_line();
792865
forum_entry_widget(0, zMimetype, zContent);
793866
}
794867
if( !isDelete ){
795868
@ <input type="submit" name="preview" value="Preview">
796869
}
797870
--- src/forum.c
+++ src/forum.c
@@ -631,10 +631,79 @@
631 @ rows="25" wrap="virtual">%h(zContent)</textarea><br>
632 }
633
634 /*
635 ** WEBPAGE: forumnew
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
636 **
637 ** Start a new forum thread.
638 */
639 void forumnew_page(void){
640 const char *zTitle = PDT("title","");
@@ -651,11 +720,13 @@
651 if( P("preview") ){
652 @ <h1>Preview:</h1>
653 forum_render(zTitle, zMimetype, zContent, "forumEdit");
654 }
655 style_header("New Forum Thread");
656 @ <form action="%R/%s(g.zPath)" method="POST">
 
 
657 forum_entry_widget(zTitle, zMimetype, zContent);
658 @ <input type="submit" name="preview" value="Preview">
659 if( P("preview") ){
660 @ <input type="submit" name="submit" value="Submit">
661 }else{
@@ -675,16 +746,16 @@
675 @ </form>
676 style_footer();
677 }
678
679 /*
680 ** WEBPAGE: forumedit
681 **
682 ** Edit an existing forum message.
683 ** Query parameters:
684 **
685 ** name=X Hash of the post to be editted. REQUIRED
686 */
687 void forumedit_page(void){
688 int fpid;
689 Manifest *pPost;
690 const char *zMimetype = 0;
@@ -741,11 +812,11 @@
741 @ <h1>Original Post:</h1>
742 forum_render(pPost->zThreadTitle, pPost->zMimetype, pPost->zWiki,
743 "forumEdit");
744 @ <h1>Change Into:</h1>
745 forum_render(zTitle, zMimetype, zContent,"forumEdit");
746 @ <form action="%R/forumedit" method="POST">
747 @ <input type="hidden" name="fpid" value="%h(P("fpid"))">
748 @ <input type="hidden" name="nullout" value="1">
749 @ <input type="hidden" name="mimetype" value="%h(zMimetype)">
750 @ <input type="hidden" name="content" value="%h(zContent)">
751 if( zTitle ){
@@ -767,14 +838,15 @@
767 "forumEdit");
768 if( P("preview") ){
769 @ <h1>Preview Of Editted Post:</h1>
770 forum_render(zTitle, zMimetype, zContent,"forumEdit");
771 }
772 @ <h1>Enter A Reply:</h1>
773 @ <form action="%R/forumedit" method="POST">
774 @ <input type="hidden" name="fpid" value="%h(P("fpid"))">
775 @ <input type="hidden" name="edit" value="1">
 
776 forum_entry_widget(zTitle, zMimetype, zContent);
777 }else{
778 /* Reply */
779 zMimetype = PD("mimetype","text/x-fossil-wiki");
780 zContent = PDT("content","");
@@ -783,14 +855,15 @@
783 forum_render(0, pPost->zMimetype, pPost->zWiki, "forumEdit");
784 if( P("preview") ){
785 @ <h1>Preview:</h1>
786 forum_render(0, zMimetype,zContent, "forumEdit");
787 }
788 @ <h1>Enter A Reply:</h1>
789 @ <form action="%R/forumedit" method="POST">
790 @ <input type="hidden" name="fpid" value="%h(P("fpid"))">
791 @ <input type="hidden" name="reply" value="1">
 
792 forum_entry_widget(0, zMimetype, zContent);
793 }
794 if( !isDelete ){
795 @ <input type="submit" name="preview" value="Preview">
796 }
797
--- src/forum.c
+++ src/forum.c
@@ -631,10 +631,79 @@
631 @ rows="25" wrap="virtual">%h(zContent)</textarea><br>
632 }
633
634 /*
635 ** WEBPAGE: forumnew
636 ** WEBPAGE: forumedit
637 **
638 ** Start a new thread on the forum or reply to an existing thread.
639 ** But first prompt to see if the user would like to log in.
640 */
641 void forum_page_init(void){
642 int isEdit;
643 char *zGoto;
644 login_check_credentials();
645 if( !g.perm.WrForum ){
646 login_needed(g.anon.WrForum);
647 return;
648 }
649 if( sqlite3_strglob("*edit*", g.zPath)==0 ){
650 zGoto = mprintf("%R/forume2?fpid=%S",PD("fpid",""));
651 isEdit = 1;
652 }else{
653 zGoto = mprintf("%R/forume1");
654 isEdit = 0;
655 }
656 if( login_is_individual() ){
657 if( isEdit ){
658 forumedit_page();
659 }else{
660 forumnew_page();
661 }
662 return;
663 }
664 style_header("%h As Anonymous?", isEdit ? "Reply" : "Post");
665 @ <p>You are not logged in.
666 @ <p><table border="0" cellpadding="10">
667 @ <tr><td>
668 @ <form action="%s(zGoto)" method="POST">
669 @ <input type="submit" value="Remain Anonymous">
670 @ </form>
671 @ <td>Post to the forum anonymously
672 if( login_self_register_available(0) ){
673 @ <tr><td>
674 @ <form action="%R/register" method="POST">
675 @ <input type="hidden" name="g" value="%s(zGoto)">
676 @ <input type="submit" value="Create An Account">
677 @ </form>
678 @ <td>Create a new account and post using that new account
679 }
680 @ <tr><td>
681 @ <form action="%R/login" method="POST">
682 @ <input type="hidden" name="g" value="%s(zGoto)">
683 @ <input type="hidden" name="noanon" value="1">
684 @ <input type="submit" value="Login">
685 @ </form>
686 @ <td>Log into an existing account
687 @ </table>
688 style_footer();
689 fossil_free(zGoto);
690 }
691
692 /*
693 ** Write the "From: USER" line on the webpage.
694 */
695 static void forum_from_line(void){
696 if( login_is_nobody() ){
697 @ From: anonymous<br>
698 }else{
699 @ From: %h(login_name())<br>
700 }
701 }
702
703 /*
704 ** WEBPAGE: forume1
705 **
706 ** Start a new forum thread.
707 */
708 void forumnew_page(void){
709 const char *zTitle = PDT("title","");
@@ -651,11 +720,13 @@
720 if( P("preview") ){
721 @ <h1>Preview:</h1>
722 forum_render(zTitle, zMimetype, zContent, "forumEdit");
723 }
724 style_header("New Forum Thread");
725 @ <form action="%R/forume1" method="POST">
726 @ <h1>New Message:</h1>
727 forum_from_line();
728 forum_entry_widget(zTitle, zMimetype, zContent);
729 @ <input type="submit" name="preview" value="Preview">
730 if( P("preview") ){
731 @ <input type="submit" name="submit" value="Submit">
732 }else{
@@ -675,16 +746,16 @@
746 @ </form>
747 style_footer();
748 }
749
750 /*
751 ** WEBPAGE: forume2
752 **
753 ** Edit an existing forum message.
754 ** Query parameters:
755 **
756 ** fpid=X Hash of the post to be editted. REQUIRED
757 */
758 void forumedit_page(void){
759 int fpid;
760 Manifest *pPost;
761 const char *zMimetype = 0;
@@ -741,11 +812,11 @@
812 @ <h1>Original Post:</h1>
813 forum_render(pPost->zThreadTitle, pPost->zMimetype, pPost->zWiki,
814 "forumEdit");
815 @ <h1>Change Into:</h1>
816 forum_render(zTitle, zMimetype, zContent,"forumEdit");
817 @ <form action="%R/forume2" method="POST">
818 @ <input type="hidden" name="fpid" value="%h(P("fpid"))">
819 @ <input type="hidden" name="nullout" value="1">
820 @ <input type="hidden" name="mimetype" value="%h(zMimetype)">
821 @ <input type="hidden" name="content" value="%h(zContent)">
822 if( zTitle ){
@@ -767,14 +838,15 @@
838 "forumEdit");
839 if( P("preview") ){
840 @ <h1>Preview Of Editted Post:</h1>
841 forum_render(zTitle, zMimetype, zContent,"forumEdit");
842 }
843 @ <h1>Revised Message:</h1>
844 @ <form action="%R/forume2" method="POST">
845 @ <input type="hidden" name="fpid" value="%h(P("fpid"))">
846 @ <input type="hidden" name="edit" value="1">
847 forum_from_line();
848 forum_entry_widget(zTitle, zMimetype, zContent);
849 }else{
850 /* Reply */
851 zMimetype = PD("mimetype","text/x-fossil-wiki");
852 zContent = PDT("content","");
@@ -783,14 +855,15 @@
855 forum_render(0, pPost->zMimetype, pPost->zWiki, "forumEdit");
856 if( P("preview") ){
857 @ <h1>Preview:</h1>
858 forum_render(0, zMimetype,zContent, "forumEdit");
859 }
860 @ <h1>Enter Reply:</h1>
861 @ <form action="%R/forume2" method="POST">
862 @ <input type="hidden" name="fpid" value="%h(P("fpid"))">
863 @ <input type="hidden" name="reply" value="1">
864 forum_from_line();
865 forum_entry_widget(0, zMimetype, zContent);
866 }
867 if( !isDelete ){
868 @ <input type="submit" name="preview" value="Preview">
869 }
870
+4 -3
--- src/login.c
+++ src/login.c
@@ -516,10 +516,11 @@
516516
char *zErrMsg = "";
517517
int uid; /* User id logged in user */
518518
char *zSha1Pw;
519519
const char *zIpAddr; /* IP address of requestor */
520520
const char *zReferer;
521
+ int noAnon = P("noanon")!=0;
521522
522523
login_check_credentials();
523524
if( login_wants_https_redirect() ){
524525
const char *zQS = P("QUERY_STRING");
525526
if( P("redir")!=0 ){
@@ -655,11 +656,11 @@
655656
}
656657
}
657658
style_header("Login/Logout");
658659
style_adunit_config(ADUNIT_OFF);
659660
@ %s(zErrMsg)
660
- if( zGoto ){
661
+ if( zGoto && !noAnon ){
661662
char *zAbbrev = fossil_strdup(zGoto);
662663
int i;
663664
for(i=0; zAbbrev[i] && zAbbrev[i]!='?'; i++){}
664665
zAbbrev[i] = 0;
665666
if( g.zLogin ){
@@ -727,20 +728,20 @@
727728
@ <td></td>
728729
@ <td><input type="submit" name="in" value="Login"></td>
729730
@ <td colspan="2">&larr; Pressing this button grants\
730731
@ permission to store a cookie
731732
@ </tr>
732
- if( login_self_register_available(0) ){
733
+ if( !noAnon && login_self_register_available(0) ){
733734
@ <tr>
734735
@ <td></td>
735736
@ <td><input type="submit" name="self" value="Create A New Account">
736737
@ <td colspan="2"> \
737738
@ &larr; Don't have a login? Click this button to create one.
738739
@ </tr>
739740
}
740741
@ </table>
741
- if( zAnonPw ){
742
+ if( zAnonPw && !noAnon ){
742743
unsigned int uSeed = captcha_seed();
743744
const char *zDecoded = captcha_decode(uSeed);
744745
int bAutoCaptcha = db_get_boolean("auto-captcha", 0);
745746
char *zCaptcha = captcha_render(zDecoded);
746747
747748
--- src/login.c
+++ src/login.c
@@ -516,10 +516,11 @@
516 char *zErrMsg = "";
517 int uid; /* User id logged in user */
518 char *zSha1Pw;
519 const char *zIpAddr; /* IP address of requestor */
520 const char *zReferer;
 
521
522 login_check_credentials();
523 if( login_wants_https_redirect() ){
524 const char *zQS = P("QUERY_STRING");
525 if( P("redir")!=0 ){
@@ -655,11 +656,11 @@
655 }
656 }
657 style_header("Login/Logout");
658 style_adunit_config(ADUNIT_OFF);
659 @ %s(zErrMsg)
660 if( zGoto ){
661 char *zAbbrev = fossil_strdup(zGoto);
662 int i;
663 for(i=0; zAbbrev[i] && zAbbrev[i]!='?'; i++){}
664 zAbbrev[i] = 0;
665 if( g.zLogin ){
@@ -727,20 +728,20 @@
727 @ <td></td>
728 @ <td><input type="submit" name="in" value="Login"></td>
729 @ <td colspan="2">&larr; Pressing this button grants\
730 @ permission to store a cookie
731 @ </tr>
732 if( login_self_register_available(0) ){
733 @ <tr>
734 @ <td></td>
735 @ <td><input type="submit" name="self" value="Create A New Account">
736 @ <td colspan="2"> \
737 @ &larr; Don't have a login? Click this button to create one.
738 @ </tr>
739 }
740 @ </table>
741 if( zAnonPw ){
742 unsigned int uSeed = captcha_seed();
743 const char *zDecoded = captcha_decode(uSeed);
744 int bAutoCaptcha = db_get_boolean("auto-captcha", 0);
745 char *zCaptcha = captcha_render(zDecoded);
746
747
--- src/login.c
+++ src/login.c
@@ -516,10 +516,11 @@
516 char *zErrMsg = "";
517 int uid; /* User id logged in user */
518 char *zSha1Pw;
519 const char *zIpAddr; /* IP address of requestor */
520 const char *zReferer;
521 int noAnon = P("noanon")!=0;
522
523 login_check_credentials();
524 if( login_wants_https_redirect() ){
525 const char *zQS = P("QUERY_STRING");
526 if( P("redir")!=0 ){
@@ -655,11 +656,11 @@
656 }
657 }
658 style_header("Login/Logout");
659 style_adunit_config(ADUNIT_OFF);
660 @ %s(zErrMsg)
661 if( zGoto && !noAnon ){
662 char *zAbbrev = fossil_strdup(zGoto);
663 int i;
664 for(i=0; zAbbrev[i] && zAbbrev[i]!='?'; i++){}
665 zAbbrev[i] = 0;
666 if( g.zLogin ){
@@ -727,20 +728,20 @@
728 @ <td></td>
729 @ <td><input type="submit" name="in" value="Login"></td>
730 @ <td colspan="2">&larr; Pressing this button grants\
731 @ permission to store a cookie
732 @ </tr>
733 if( !noAnon && login_self_register_available(0) ){
734 @ <tr>
735 @ <td></td>
736 @ <td><input type="submit" name="self" value="Create A New Account">
737 @ <td colspan="2"> \
738 @ &larr; Don't have a login? Click this button to create one.
739 @ </tr>
740 }
741 @ </table>
742 if( zAnonPw && !noAnon ){
743 unsigned int uSeed = captcha_seed();
744 const char *zDecoded = captcha_decode(uSeed);
745 int bAutoCaptcha = db_get_boolean("auto-captcha", 0);
746 char *zCaptcha = captcha_render(zDecoded);
747
748

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button