Fossil SCM
Further progress toward get email subscription webpages working.
Commit
adf068faebbe64f380066e8c3ffe58ae976a2e23ad1fdc10e77583c144863c3c
Parent
31be2e17a4833ce…
1 file changed
+74
-32
+74
-32
| --- src/email.c | ||
| +++ src/email.c | ||
| @@ -50,11 +50,11 @@ | ||
| 50 | 50 | @ CREATE TABLE repository.subscriber( |
| 51 | 51 | @ subscriberId INTEGER PRIMARY KEY, -- numeric subscriber ID. Internal use |
| 52 | 52 | @ subscriberCode BLOB UNIQUE, -- UUID for subscriber. External use |
| 53 | 53 | @ semail TEXT UNIQUE COLLATE nocase,-- email address |
| 54 | 54 | @ suname TEXT, -- corresponding USER entry |
| 55 | -@ sverify BOOLEAN, -- email address verified | |
| 55 | +@ sverified BOOLEAN, -- email address verified | |
| 56 | 56 | @ sdonotcall BOOLEAN, -- true for Do Not Call |
| 57 | 57 | @ sdigest BOOLEAN, -- true for daily digests only |
| 58 | 58 | @ ssub TEXT, -- baseline subscriptions |
| 59 | 59 | @ sctime DATE, -- When this entry was created. JulianDay |
| 60 | 60 | @ smtime DATE, -- Last change. JulianDay |
| @@ -525,16 +525,16 @@ | ||
| 525 | 525 | /* |
| 526 | 526 | ** Text of email message sent in order to confirm a subscription. |
| 527 | 527 | */ |
| 528 | 528 | static const char zConfirmMsg[] = |
| 529 | 529 | @ Someone has signed you up for email alerts on the Fossil repository |
| 530 | -@ at %R. | |
| 530 | +@ at %s. | |
| 531 | 531 | @ |
| 532 | 532 | @ To confirm your subscription and begin receiving alerts, click on |
| 533 | 533 | @ the following hyperlink: |
| 534 | 534 | @ |
| 535 | -@ %R/alerts/%s | |
| 535 | +@ %s/alerts/%s | |
| 536 | 536 | @ |
| 537 | 537 | @ Save the hyperlink above! You can reuse this same hyperlink to |
| 538 | 538 | @ unsubscribe or to change the kinds of alerts you receive. |
| 539 | 539 | @ |
| 540 | 540 | @ If you do not want to subscribe, you can simply ignore this message. |
| @@ -586,16 +586,16 @@ | ||
| 586 | 586 | if( PB("st") ) ssub[nsub++] = 't'; |
| 587 | 587 | if( PB("sw") ) ssub[nsub++] = 'w'; |
| 588 | 588 | ssub[nsub] = 0; |
| 589 | 589 | db_multi_exec( |
| 590 | 590 | "INSERT INTO subscriber(subscriberCode,semail,suname," |
| 591 | - " sverify,sdonotcall,sdigest,ssub,sctime,smtime,smip)" | |
| 591 | + " sverified,sdonotcall,sdigest,ssub,sctime,smtime,smip)" | |
| 592 | 592 | "VALUES(randomblob(32),%Q,%Q,%d,0,%d,%Q," |
| 593 | 593 | " julianday('now'),julianday('now'),%Q)", |
| 594 | 594 | /* semail */ zEAddr, |
| 595 | 595 | /* suname */ needCaptcha==0 ? g.zLogin : 0, |
| 596 | - /* sverify */ needCaptcha==0, | |
| 596 | + /* sverified */ needCaptcha==0, | |
| 597 | 597 | /* sdigest */ PB("di"), |
| 598 | 598 | /* ssub */ ssub, |
| 599 | 599 | /* smip */ g.zIpAddr |
| 600 | 600 | ); |
| 601 | 601 | id = db_last_insert_rowid(); |
| @@ -613,11 +613,12 @@ | ||
| 613 | 613 | Blob hdr, body; |
| 614 | 614 | blob_init(&hdr,0,0); |
| 615 | 615 | blob_init(&body,0,0); |
| 616 | 616 | blob_appendf(&hdr, "To: %s\n", zEAddr); |
| 617 | 617 | blob_appendf(&hdr, "Subject: Subscription verification\n"); |
| 618 | - blob_appendf(&body, zConfirmMsg/*works-like:"%s"*/, zCode); | |
| 618 | + blob_appendf(&body, zConfirmMsg/*works-like:"%s%s%s"*/, | |
| 619 | + g.zBaseURL, g.zBaseURL, zCode); | |
| 619 | 620 | email_send(&hdr, &body, 0, 0); |
| 620 | 621 | style_header("Email Alert Verification"); |
| 621 | 622 | @ <p>An email has been sent to "%h(zEAddr)". That email contains a |
| 622 | 623 | @ hyperlink that you must click on in order to activate your |
| 623 | 624 | @ subscription.</p> |
| @@ -713,18 +714,20 @@ | ||
| 713 | 714 | */ |
| 714 | 715 | void alerts_page(void){ |
| 715 | 716 | const char *zName = P("name"); |
| 716 | 717 | Stmt q; |
| 717 | 718 | int sa, sc, st, sw; |
| 718 | - int sdigest, sdonotcall, sverify; | |
| 719 | + int sdigest, sdonotcall, sverified; | |
| 719 | 720 | const char *ssub; |
| 720 | 721 | const char *semail; |
| 721 | 722 | const char *sctime; |
| 722 | 723 | const char *smtime; |
| 723 | 724 | const char *smip; |
| 725 | + const char *suname; | |
| 724 | 726 | int i; |
| 725 | - | |
| 727 | + int eErr = 0; | |
| 728 | + char *zErr = 0; | |
| 726 | 729 | |
| 727 | 730 | login_check_credentials(); |
| 728 | 731 | if( !g.perm.EmailAlert ){ |
| 729 | 732 | cgi_redirect("subscribe"); |
| 730 | 733 | return; |
| @@ -740,55 +743,73 @@ | ||
| 740 | 743 | if( P("submit")!=0 && cgi_csrf_safe(1) ){ |
| 741 | 744 | int sdonotcall = PB("sdonotcall"); |
| 742 | 745 | int sdigest = PB("sdigest"); |
| 743 | 746 | char ssub[10]; |
| 744 | 747 | int nsub = 0; |
| 748 | + const char *suname = 0; | |
| 745 | 749 | if( PB("sa") ) ssub[nsub++] = 'a'; |
| 746 | 750 | if( PB("sc") ) ssub[nsub++] = 'c'; |
| 747 | 751 | if( PB("st") ) ssub[nsub++] = 't'; |
| 748 | 752 | if( PB("sw") ) ssub[nsub++] = 'w'; |
| 749 | 753 | ssub[nsub] = 0; |
| 754 | + if( g.perm.Admin ){ | |
| 755 | + suname = PT("suname"); | |
| 756 | + if( suname && suname[0]==0 ) suname = 0; | |
| 757 | + } | |
| 750 | 758 | db_multi_exec( |
| 751 | 759 | "UPDATE subscriber SET" |
| 752 | 760 | " sdonotcall=%d," |
| 753 | 761 | " sdigest=%d," |
| 754 | 762 | " ssub=%Q," |
| 755 | 763 | " smtime=julianday('now')," |
| 756 | - " smip=%Q" | |
| 764 | + " smip=%Q," | |
| 765 | + " suname=COALESCE(%Q,suname)" | |
| 757 | 766 | " WHERE subscriberCode=hextoblob(%Q)", |
| 758 | 767 | sdonotcall, |
| 759 | 768 | sdigest, |
| 760 | 769 | ssub, |
| 761 | 770 | g.zIpAddr, |
| 771 | + suname, | |
| 762 | 772 | zName |
| 763 | 773 | ); |
| 764 | 774 | } |
| 765 | - if( PB("dodelete") && P("delete")!=0 && cgi_csrf_safe(1) ){ | |
| 766 | - db_multi_exec( | |
| 767 | - "DELETE FROM subscriber WHERE subscriberCode=hextoblob(%Q)", | |
| 768 | - zName | |
| 769 | - ); | |
| 775 | + if( P("delete")!=0 && cgi_csrf_safe(1) ){ | |
| 776 | + if( !PB("dodelete") ){ | |
| 777 | + eErr = 9; | |
| 778 | + zErr = mprintf("Select this checkbox and press \"Unsubscribe\" to" | |
| 779 | + " unsubscribe"); | |
| 780 | + }else{ | |
| 781 | + db_multi_exec( | |
| 782 | + "DELETE FROM subscriber WHERE subscriberCode=hextoblob(%Q)", | |
| 783 | + zName | |
| 784 | + ); | |
| 785 | + style_header("Email Subscription Deleted"); | |
| 786 | + @ <p>The email subscription has been deleted</p> | |
| 787 | + style_footer(); | |
| 788 | + return; | |
| 789 | + } | |
| 770 | 790 | } |
| 771 | 791 | db_prepare(&q, |
| 772 | 792 | "SELECT" |
| 773 | 793 | " semail," |
| 774 | - " sverify," | |
| 794 | + " sverified," | |
| 775 | 795 | " sdonotcall," |
| 776 | 796 | " sdigest," |
| 777 | 797 | " ssub," |
| 778 | 798 | " datetime(sctime)," |
| 779 | 799 | " datetime(smtime)," |
| 780 | - " smip" | |
| 800 | + " smip," | |
| 801 | + " suname" | |
| 781 | 802 | " FROM subscriber WHERE subscriberCode=hextoblob(%Q)", zName); |
| 782 | 803 | if( db_step(&q)!=SQLITE_ROW ){ |
| 783 | 804 | db_finalize(&q); |
| 784 | 805 | cgi_redirect("subscribe"); |
| 785 | 806 | return; |
| 786 | 807 | } |
| 787 | 808 | style_header("Update Subscription"); |
| 788 | 809 | semail = db_column_text(&q, 0); |
| 789 | - sverify = db_column_int(&q, 1); | |
| 810 | + sverified = db_column_int(&q, 1); | |
| 790 | 811 | sdonotcall = db_column_int(&q, 2); |
| 791 | 812 | sdigest = db_column_int(&q, 3); |
| 792 | 813 | ssub = db_column_text(&q, 4); |
| 793 | 814 | sa = strchr(ssub,'a')!=0; |
| 794 | 815 | sc = strchr(ssub,'c')!=0; |
| @@ -795,11 +816,25 @@ | ||
| 795 | 816 | st = strchr(ssub,'t')!=0; |
| 796 | 817 | sw = strchr(ssub,'w')!=0; |
| 797 | 818 | sctime = db_column_text(&q, 5); |
| 798 | 819 | smtime = db_column_text(&q, 6); |
| 799 | 820 | smip = db_column_text(&q, 7); |
| 821 | + suname = db_column_text(&q, 8); | |
| 822 | + if( !g.perm.Admin && !sverified ){ | |
| 823 | + db_multi_exec( | |
| 824 | + "UPDATE subscriber SET sverified=1 WHERE subscriberCode=hextoblob(%Q)", | |
| 825 | + zName); | |
| 826 | + @ <h1>Your email alert subscription has been verified!</h1> | |
| 827 | + @ <p>Use the form below to update your subscription information.</p> | |
| 828 | + @ <p>Hint: Bookmark this page so that you can more easily update | |
| 829 | + @ your subscription information in the future</p> | |
| 830 | + }else{ | |
| 831 | + @ <p>Make changes to the email subscription shown below and | |
| 832 | + @ press "Submit".</p> | |
| 833 | + } | |
| 800 | 834 | form_begin(0, "%R/alerts"); |
| 835 | + @ <input type="hidden" name="name" value="%h(zName)"> | |
| 801 | 836 | @ <table class="subscribe"> |
| 802 | 837 | @ <tr> |
| 803 | 838 | @ <td class="form_label">Email Address:</td> |
| 804 | 839 | @ <td>%h(semail)</td> |
| 805 | 840 | @ </tr> |
| @@ -806,40 +841,47 @@ | ||
| 806 | 841 | if( g.perm.Admin ){ |
| 807 | 842 | @ <tr> |
| 808 | 843 | @ <td class='form_label'>IP Address:</td> |
| 809 | 844 | @ <td>%h(smip)</td> |
| 810 | 845 | @ </tr> |
| 846 | + @ <tr> | |
| 847 | + @ <td class='form_label'>User:</td> | |
| 848 | + @ <td>%h(suname?suname:"")</td> | |
| 849 | + @ </tr> | |
| 811 | 850 | } |
| 812 | 851 | @ <tr> |
| 813 | 852 | @ <td class="form_label">Options:</td> |
| 814 | - @ <td><label><input type="checkbox" name="sa" value="%d(sa)">\ | |
| 853 | + @ <td><label><input type="checkbox" name="sa" %s(sa?"checked":"")>\ | |
| 815 | 854 | @ Announcements</label><br> |
| 816 | - @ <label><input type="checkbox" name="sc" value="%d(sc)">\ | |
| 855 | + @ <label><input type="checkbox" name="sc" %s(sc?"checked":"")>\ | |
| 817 | 856 | @ Check-ins</label><br> |
| 818 | - @ <label><input type="checkbox" name="st" value="%d(st)">\ | |
| 857 | + @ <label><input type="checkbox" name="st" %s(st?"checked":"")>\ | |
| 819 | 858 | @ Ticket changes</label><br> |
| 820 | - @ <label><input type="checkbox" name="sw" value="%d(sw)">\ | |
| 859 | + @ <label><input type="checkbox" name="sw" %s(sw?"checked":"")>\ | |
| 821 | 860 | @ Wiki</label><br> |
| 822 | - @ <label><input type="checkbox" name="sdigest" value="%d(sdigest)">\ | |
| 861 | + @ <label><input type="checkbox" name="sdigest" %s(sdigest?"checked":"")>\ | |
| 823 | 862 | @ Daily digest only</label><br> |
| 824 | 863 | if( g.perm.Admin ){ |
| 825 | - @ <label><input type="checkbox" name="sdonotcall" value="%d(sdonotcall)">\ | |
| 826 | - @ Do not call</label><br> | |
| 827 | - @ <label><input type="checkbox" name="sverify" value="%d(sverify)">\ | |
| 864 | + @ <label><input type="checkbox" name="sdonotcall" \ | |
| 865 | + @ %s(sdonotcall?"checked":"")>Do not call</label><br> | |
| 866 | + @ <label><input type="checkbox" name="sverified" \ | |
| 867 | + @ %s(sverified?"checked":"")>\ | |
| 828 | 868 | @ Verified</label><br> |
| 829 | 869 | } |
| 870 | + @ <label><input type="checkbox" name="dodelete"> | |
| 871 | + @ Unsubscribe</label> \ | |
| 872 | + if( eErr==9 ){ | |
| 873 | + @ <span class="loginError">← %h(zErr)</span>\ | |
| 874 | + } | |
| 875 | + @ <br> | |
| 830 | 876 | @ </td></tr> |
| 831 | 877 | @ <tr> |
| 832 | 878 | @ <td></td> |
| 833 | - @ <td><input type="submit" value="Submit"></td> | |
| 834 | - @ </tr> | |
| 835 | - @ <tr> | |
| 836 | - @ <td></td> | |
| 837 | - @ <td><label><input type="checkbox" name="dodelete" value="0"> | |
| 838 | - @ Delete this subscription</label> | |
| 839 | - @ <input type="submit" name="delete" value="Delete"></td> | |
| 879 | + @ <td><input type="submit" name="submit" value="Submit"> | |
| 880 | + @ <input type="submit" name="delete" value="Unsubscribe"> | |
| 840 | 881 | @ </tr> |
| 841 | 882 | @ </table> |
| 842 | 883 | @ </form> |
| 884 | + fossil_free(zErr); | |
| 843 | 885 | db_finalize(&q); |
| 844 | 886 | style_footer(); |
| 845 | 887 | } |
| 846 | 888 |
| --- src/email.c | |
| +++ src/email.c | |
| @@ -50,11 +50,11 @@ | |
| 50 | @ CREATE TABLE repository.subscriber( |
| 51 | @ subscriberId INTEGER PRIMARY KEY, -- numeric subscriber ID. Internal use |
| 52 | @ subscriberCode BLOB UNIQUE, -- UUID for subscriber. External use |
| 53 | @ semail TEXT UNIQUE COLLATE nocase,-- email address |
| 54 | @ suname TEXT, -- corresponding USER entry |
| 55 | @ sverify BOOLEAN, -- email address verified |
| 56 | @ sdonotcall BOOLEAN, -- true for Do Not Call |
| 57 | @ sdigest BOOLEAN, -- true for daily digests only |
| 58 | @ ssub TEXT, -- baseline subscriptions |
| 59 | @ sctime DATE, -- When this entry was created. JulianDay |
| 60 | @ smtime DATE, -- Last change. JulianDay |
| @@ -525,16 +525,16 @@ | |
| 525 | /* |
| 526 | ** Text of email message sent in order to confirm a subscription. |
| 527 | */ |
| 528 | static const char zConfirmMsg[] = |
| 529 | @ Someone has signed you up for email alerts on the Fossil repository |
| 530 | @ at %R. |
| 531 | @ |
| 532 | @ To confirm your subscription and begin receiving alerts, click on |
| 533 | @ the following hyperlink: |
| 534 | @ |
| 535 | @ %R/alerts/%s |
| 536 | @ |
| 537 | @ Save the hyperlink above! You can reuse this same hyperlink to |
| 538 | @ unsubscribe or to change the kinds of alerts you receive. |
| 539 | @ |
| 540 | @ If you do not want to subscribe, you can simply ignore this message. |
| @@ -586,16 +586,16 @@ | |
| 586 | if( PB("st") ) ssub[nsub++] = 't'; |
| 587 | if( PB("sw") ) ssub[nsub++] = 'w'; |
| 588 | ssub[nsub] = 0; |
| 589 | db_multi_exec( |
| 590 | "INSERT INTO subscriber(subscriberCode,semail,suname," |
| 591 | " sverify,sdonotcall,sdigest,ssub,sctime,smtime,smip)" |
| 592 | "VALUES(randomblob(32),%Q,%Q,%d,0,%d,%Q," |
| 593 | " julianday('now'),julianday('now'),%Q)", |
| 594 | /* semail */ zEAddr, |
| 595 | /* suname */ needCaptcha==0 ? g.zLogin : 0, |
| 596 | /* sverify */ needCaptcha==0, |
| 597 | /* sdigest */ PB("di"), |
| 598 | /* ssub */ ssub, |
| 599 | /* smip */ g.zIpAddr |
| 600 | ); |
| 601 | id = db_last_insert_rowid(); |
| @@ -613,11 +613,12 @@ | |
| 613 | Blob hdr, body; |
| 614 | blob_init(&hdr,0,0); |
| 615 | blob_init(&body,0,0); |
| 616 | blob_appendf(&hdr, "To: %s\n", zEAddr); |
| 617 | blob_appendf(&hdr, "Subject: Subscription verification\n"); |
| 618 | blob_appendf(&body, zConfirmMsg/*works-like:"%s"*/, zCode); |
| 619 | email_send(&hdr, &body, 0, 0); |
| 620 | style_header("Email Alert Verification"); |
| 621 | @ <p>An email has been sent to "%h(zEAddr)". That email contains a |
| 622 | @ hyperlink that you must click on in order to activate your |
| 623 | @ subscription.</p> |
| @@ -713,18 +714,20 @@ | |
| 713 | */ |
| 714 | void alerts_page(void){ |
| 715 | const char *zName = P("name"); |
| 716 | Stmt q; |
| 717 | int sa, sc, st, sw; |
| 718 | int sdigest, sdonotcall, sverify; |
| 719 | const char *ssub; |
| 720 | const char *semail; |
| 721 | const char *sctime; |
| 722 | const char *smtime; |
| 723 | const char *smip; |
| 724 | int i; |
| 725 | |
| 726 | |
| 727 | login_check_credentials(); |
| 728 | if( !g.perm.EmailAlert ){ |
| 729 | cgi_redirect("subscribe"); |
| 730 | return; |
| @@ -740,55 +743,73 @@ | |
| 740 | if( P("submit")!=0 && cgi_csrf_safe(1) ){ |
| 741 | int sdonotcall = PB("sdonotcall"); |
| 742 | int sdigest = PB("sdigest"); |
| 743 | char ssub[10]; |
| 744 | int nsub = 0; |
| 745 | if( PB("sa") ) ssub[nsub++] = 'a'; |
| 746 | if( PB("sc") ) ssub[nsub++] = 'c'; |
| 747 | if( PB("st") ) ssub[nsub++] = 't'; |
| 748 | if( PB("sw") ) ssub[nsub++] = 'w'; |
| 749 | ssub[nsub] = 0; |
| 750 | db_multi_exec( |
| 751 | "UPDATE subscriber SET" |
| 752 | " sdonotcall=%d," |
| 753 | " sdigest=%d," |
| 754 | " ssub=%Q," |
| 755 | " smtime=julianday('now')," |
| 756 | " smip=%Q" |
| 757 | " WHERE subscriberCode=hextoblob(%Q)", |
| 758 | sdonotcall, |
| 759 | sdigest, |
| 760 | ssub, |
| 761 | g.zIpAddr, |
| 762 | zName |
| 763 | ); |
| 764 | } |
| 765 | if( PB("dodelete") && P("delete")!=0 && cgi_csrf_safe(1) ){ |
| 766 | db_multi_exec( |
| 767 | "DELETE FROM subscriber WHERE subscriberCode=hextoblob(%Q)", |
| 768 | zName |
| 769 | ); |
| 770 | } |
| 771 | db_prepare(&q, |
| 772 | "SELECT" |
| 773 | " semail," |
| 774 | " sverify," |
| 775 | " sdonotcall," |
| 776 | " sdigest," |
| 777 | " ssub," |
| 778 | " datetime(sctime)," |
| 779 | " datetime(smtime)," |
| 780 | " smip" |
| 781 | " FROM subscriber WHERE subscriberCode=hextoblob(%Q)", zName); |
| 782 | if( db_step(&q)!=SQLITE_ROW ){ |
| 783 | db_finalize(&q); |
| 784 | cgi_redirect("subscribe"); |
| 785 | return; |
| 786 | } |
| 787 | style_header("Update Subscription"); |
| 788 | semail = db_column_text(&q, 0); |
| 789 | sverify = db_column_int(&q, 1); |
| 790 | sdonotcall = db_column_int(&q, 2); |
| 791 | sdigest = db_column_int(&q, 3); |
| 792 | ssub = db_column_text(&q, 4); |
| 793 | sa = strchr(ssub,'a')!=0; |
| 794 | sc = strchr(ssub,'c')!=0; |
| @@ -795,11 +816,25 @@ | |
| 795 | st = strchr(ssub,'t')!=0; |
| 796 | sw = strchr(ssub,'w')!=0; |
| 797 | sctime = db_column_text(&q, 5); |
| 798 | smtime = db_column_text(&q, 6); |
| 799 | smip = db_column_text(&q, 7); |
| 800 | form_begin(0, "%R/alerts"); |
| 801 | @ <table class="subscribe"> |
| 802 | @ <tr> |
| 803 | @ <td class="form_label">Email Address:</td> |
| 804 | @ <td>%h(semail)</td> |
| 805 | @ </tr> |
| @@ -806,40 +841,47 @@ | |
| 806 | if( g.perm.Admin ){ |
| 807 | @ <tr> |
| 808 | @ <td class='form_label'>IP Address:</td> |
| 809 | @ <td>%h(smip)</td> |
| 810 | @ </tr> |
| 811 | } |
| 812 | @ <tr> |
| 813 | @ <td class="form_label">Options:</td> |
| 814 | @ <td><label><input type="checkbox" name="sa" value="%d(sa)">\ |
| 815 | @ Announcements</label><br> |
| 816 | @ <label><input type="checkbox" name="sc" value="%d(sc)">\ |
| 817 | @ Check-ins</label><br> |
| 818 | @ <label><input type="checkbox" name="st" value="%d(st)">\ |
| 819 | @ Ticket changes</label><br> |
| 820 | @ <label><input type="checkbox" name="sw" value="%d(sw)">\ |
| 821 | @ Wiki</label><br> |
| 822 | @ <label><input type="checkbox" name="sdigest" value="%d(sdigest)">\ |
| 823 | @ Daily digest only</label><br> |
| 824 | if( g.perm.Admin ){ |
| 825 | @ <label><input type="checkbox" name="sdonotcall" value="%d(sdonotcall)">\ |
| 826 | @ Do not call</label><br> |
| 827 | @ <label><input type="checkbox" name="sverify" value="%d(sverify)">\ |
| 828 | @ Verified</label><br> |
| 829 | } |
| 830 | @ </td></tr> |
| 831 | @ <tr> |
| 832 | @ <td></td> |
| 833 | @ <td><input type="submit" value="Submit"></td> |
| 834 | @ </tr> |
| 835 | @ <tr> |
| 836 | @ <td></td> |
| 837 | @ <td><label><input type="checkbox" name="dodelete" value="0"> |
| 838 | @ Delete this subscription</label> |
| 839 | @ <input type="submit" name="delete" value="Delete"></td> |
| 840 | @ </tr> |
| 841 | @ </table> |
| 842 | @ </form> |
| 843 | db_finalize(&q); |
| 844 | style_footer(); |
| 845 | } |
| 846 |
| --- src/email.c | |
| +++ src/email.c | |
| @@ -50,11 +50,11 @@ | |
| 50 | @ CREATE TABLE repository.subscriber( |
| 51 | @ subscriberId INTEGER PRIMARY KEY, -- numeric subscriber ID. Internal use |
| 52 | @ subscriberCode BLOB UNIQUE, -- UUID for subscriber. External use |
| 53 | @ semail TEXT UNIQUE COLLATE nocase,-- email address |
| 54 | @ suname TEXT, -- corresponding USER entry |
| 55 | @ sverified BOOLEAN, -- email address verified |
| 56 | @ sdonotcall BOOLEAN, -- true for Do Not Call |
| 57 | @ sdigest BOOLEAN, -- true for daily digests only |
| 58 | @ ssub TEXT, -- baseline subscriptions |
| 59 | @ sctime DATE, -- When this entry was created. JulianDay |
| 60 | @ smtime DATE, -- Last change. JulianDay |
| @@ -525,16 +525,16 @@ | |
| 525 | /* |
| 526 | ** Text of email message sent in order to confirm a subscription. |
| 527 | */ |
| 528 | static const char zConfirmMsg[] = |
| 529 | @ Someone has signed you up for email alerts on the Fossil repository |
| 530 | @ at %s. |
| 531 | @ |
| 532 | @ To confirm your subscription and begin receiving alerts, click on |
| 533 | @ the following hyperlink: |
| 534 | @ |
| 535 | @ %s/alerts/%s |
| 536 | @ |
| 537 | @ Save the hyperlink above! You can reuse this same hyperlink to |
| 538 | @ unsubscribe or to change the kinds of alerts you receive. |
| 539 | @ |
| 540 | @ If you do not want to subscribe, you can simply ignore this message. |
| @@ -586,16 +586,16 @@ | |
| 586 | if( PB("st") ) ssub[nsub++] = 't'; |
| 587 | if( PB("sw") ) ssub[nsub++] = 'w'; |
| 588 | ssub[nsub] = 0; |
| 589 | db_multi_exec( |
| 590 | "INSERT INTO subscriber(subscriberCode,semail,suname," |
| 591 | " sverified,sdonotcall,sdigest,ssub,sctime,smtime,smip)" |
| 592 | "VALUES(randomblob(32),%Q,%Q,%d,0,%d,%Q," |
| 593 | " julianday('now'),julianday('now'),%Q)", |
| 594 | /* semail */ zEAddr, |
| 595 | /* suname */ needCaptcha==0 ? g.zLogin : 0, |
| 596 | /* sverified */ needCaptcha==0, |
| 597 | /* sdigest */ PB("di"), |
| 598 | /* ssub */ ssub, |
| 599 | /* smip */ g.zIpAddr |
| 600 | ); |
| 601 | id = db_last_insert_rowid(); |
| @@ -613,11 +613,12 @@ | |
| 613 | Blob hdr, body; |
| 614 | blob_init(&hdr,0,0); |
| 615 | blob_init(&body,0,0); |
| 616 | blob_appendf(&hdr, "To: %s\n", zEAddr); |
| 617 | blob_appendf(&hdr, "Subject: Subscription verification\n"); |
| 618 | blob_appendf(&body, zConfirmMsg/*works-like:"%s%s%s"*/, |
| 619 | g.zBaseURL, g.zBaseURL, zCode); |
| 620 | email_send(&hdr, &body, 0, 0); |
| 621 | style_header("Email Alert Verification"); |
| 622 | @ <p>An email has been sent to "%h(zEAddr)". That email contains a |
| 623 | @ hyperlink that you must click on in order to activate your |
| 624 | @ subscription.</p> |
| @@ -713,18 +714,20 @@ | |
| 714 | */ |
| 715 | void alerts_page(void){ |
| 716 | const char *zName = P("name"); |
| 717 | Stmt q; |
| 718 | int sa, sc, st, sw; |
| 719 | int sdigest, sdonotcall, sverified; |
| 720 | const char *ssub; |
| 721 | const char *semail; |
| 722 | const char *sctime; |
| 723 | const char *smtime; |
| 724 | const char *smip; |
| 725 | const char *suname; |
| 726 | int i; |
| 727 | int eErr = 0; |
| 728 | char *zErr = 0; |
| 729 | |
| 730 | login_check_credentials(); |
| 731 | if( !g.perm.EmailAlert ){ |
| 732 | cgi_redirect("subscribe"); |
| 733 | return; |
| @@ -740,55 +743,73 @@ | |
| 743 | if( P("submit")!=0 && cgi_csrf_safe(1) ){ |
| 744 | int sdonotcall = PB("sdonotcall"); |
| 745 | int sdigest = PB("sdigest"); |
| 746 | char ssub[10]; |
| 747 | int nsub = 0; |
| 748 | const char *suname = 0; |
| 749 | if( PB("sa") ) ssub[nsub++] = 'a'; |
| 750 | if( PB("sc") ) ssub[nsub++] = 'c'; |
| 751 | if( PB("st") ) ssub[nsub++] = 't'; |
| 752 | if( PB("sw") ) ssub[nsub++] = 'w'; |
| 753 | ssub[nsub] = 0; |
| 754 | if( g.perm.Admin ){ |
| 755 | suname = PT("suname"); |
| 756 | if( suname && suname[0]==0 ) suname = 0; |
| 757 | } |
| 758 | db_multi_exec( |
| 759 | "UPDATE subscriber SET" |
| 760 | " sdonotcall=%d," |
| 761 | " sdigest=%d," |
| 762 | " ssub=%Q," |
| 763 | " smtime=julianday('now')," |
| 764 | " smip=%Q," |
| 765 | " suname=COALESCE(%Q,suname)" |
| 766 | " WHERE subscriberCode=hextoblob(%Q)", |
| 767 | sdonotcall, |
| 768 | sdigest, |
| 769 | ssub, |
| 770 | g.zIpAddr, |
| 771 | suname, |
| 772 | zName |
| 773 | ); |
| 774 | } |
| 775 | if( P("delete")!=0 && cgi_csrf_safe(1) ){ |
| 776 | if( !PB("dodelete") ){ |
| 777 | eErr = 9; |
| 778 | zErr = mprintf("Select this checkbox and press \"Unsubscribe\" to" |
| 779 | " unsubscribe"); |
| 780 | }else{ |
| 781 | db_multi_exec( |
| 782 | "DELETE FROM subscriber WHERE subscriberCode=hextoblob(%Q)", |
| 783 | zName |
| 784 | ); |
| 785 | style_header("Email Subscription Deleted"); |
| 786 | @ <p>The email subscription has been deleted</p> |
| 787 | style_footer(); |
| 788 | return; |
| 789 | } |
| 790 | } |
| 791 | db_prepare(&q, |
| 792 | "SELECT" |
| 793 | " semail," |
| 794 | " sverified," |
| 795 | " sdonotcall," |
| 796 | " sdigest," |
| 797 | " ssub," |
| 798 | " datetime(sctime)," |
| 799 | " datetime(smtime)," |
| 800 | " smip," |
| 801 | " suname" |
| 802 | " FROM subscriber WHERE subscriberCode=hextoblob(%Q)", zName); |
| 803 | if( db_step(&q)!=SQLITE_ROW ){ |
| 804 | db_finalize(&q); |
| 805 | cgi_redirect("subscribe"); |
| 806 | return; |
| 807 | } |
| 808 | style_header("Update Subscription"); |
| 809 | semail = db_column_text(&q, 0); |
| 810 | sverified = db_column_int(&q, 1); |
| 811 | sdonotcall = db_column_int(&q, 2); |
| 812 | sdigest = db_column_int(&q, 3); |
| 813 | ssub = db_column_text(&q, 4); |
| 814 | sa = strchr(ssub,'a')!=0; |
| 815 | sc = strchr(ssub,'c')!=0; |
| @@ -795,11 +816,25 @@ | |
| 816 | st = strchr(ssub,'t')!=0; |
| 817 | sw = strchr(ssub,'w')!=0; |
| 818 | sctime = db_column_text(&q, 5); |
| 819 | smtime = db_column_text(&q, 6); |
| 820 | smip = db_column_text(&q, 7); |
| 821 | suname = db_column_text(&q, 8); |
| 822 | if( !g.perm.Admin && !sverified ){ |
| 823 | db_multi_exec( |
| 824 | "UPDATE subscriber SET sverified=1 WHERE subscriberCode=hextoblob(%Q)", |
| 825 | zName); |
| 826 | @ <h1>Your email alert subscription has been verified!</h1> |
| 827 | @ <p>Use the form below to update your subscription information.</p> |
| 828 | @ <p>Hint: Bookmark this page so that you can more easily update |
| 829 | @ your subscription information in the future</p> |
| 830 | }else{ |
| 831 | @ <p>Make changes to the email subscription shown below and |
| 832 | @ press "Submit".</p> |
| 833 | } |
| 834 | form_begin(0, "%R/alerts"); |
| 835 | @ <input type="hidden" name="name" value="%h(zName)"> |
| 836 | @ <table class="subscribe"> |
| 837 | @ <tr> |
| 838 | @ <td class="form_label">Email Address:</td> |
| 839 | @ <td>%h(semail)</td> |
| 840 | @ </tr> |
| @@ -806,40 +841,47 @@ | |
| 841 | if( g.perm.Admin ){ |
| 842 | @ <tr> |
| 843 | @ <td class='form_label'>IP Address:</td> |
| 844 | @ <td>%h(smip)</td> |
| 845 | @ </tr> |
| 846 | @ <tr> |
| 847 | @ <td class='form_label'>User:</td> |
| 848 | @ <td>%h(suname?suname:"")</td> |
| 849 | @ </tr> |
| 850 | } |
| 851 | @ <tr> |
| 852 | @ <td class="form_label">Options:</td> |
| 853 | @ <td><label><input type="checkbox" name="sa" %s(sa?"checked":"")>\ |
| 854 | @ Announcements</label><br> |
| 855 | @ <label><input type="checkbox" name="sc" %s(sc?"checked":"")>\ |
| 856 | @ Check-ins</label><br> |
| 857 | @ <label><input type="checkbox" name="st" %s(st?"checked":"")>\ |
| 858 | @ Ticket changes</label><br> |
| 859 | @ <label><input type="checkbox" name="sw" %s(sw?"checked":"")>\ |
| 860 | @ Wiki</label><br> |
| 861 | @ <label><input type="checkbox" name="sdigest" %s(sdigest?"checked":"")>\ |
| 862 | @ Daily digest only</label><br> |
| 863 | if( g.perm.Admin ){ |
| 864 | @ <label><input type="checkbox" name="sdonotcall" \ |
| 865 | @ %s(sdonotcall?"checked":"")>Do not call</label><br> |
| 866 | @ <label><input type="checkbox" name="sverified" \ |
| 867 | @ %s(sverified?"checked":"")>\ |
| 868 | @ Verified</label><br> |
| 869 | } |
| 870 | @ <label><input type="checkbox" name="dodelete"> |
| 871 | @ Unsubscribe</label> \ |
| 872 | if( eErr==9 ){ |
| 873 | @ <span class="loginError">← %h(zErr)</span>\ |
| 874 | } |
| 875 | @ <br> |
| 876 | @ </td></tr> |
| 877 | @ <tr> |
| 878 | @ <td></td> |
| 879 | @ <td><input type="submit" name="submit" value="Submit"> |
| 880 | @ <input type="submit" name="delete" value="Unsubscribe"> |
| 881 | @ </tr> |
| 882 | @ </table> |
| 883 | @ </form> |
| 884 | fossil_free(zErr); |
| 885 | db_finalize(&q); |
| 886 | style_footer(); |
| 887 | } |
| 888 |