Fossil SCM

Improvements to self-register (the /register page) so that it works correctly for users how are already subscribers and enter the subscriber email.

drh 2018-08-15 18:14 trunk
Commit 4c43f2cd43a0dcf40576edf0f5318fc9310d4da49dd19532987e7547bc24fbd1
1 file changed +26 -4
+26 -4
--- src/login.c
+++ src/login.c
@@ -1528,10 +1528,11 @@
15281528
char *zCaptcha;
15291529
int iErrLine = -1;
15301530
const char *zErr = 0;
15311531
char *zPerms; /* Permissions for the default user */
15321532
int canDoAlerts = 0; /* True if receiving email alerts is possible */
1533
+ int doAlerts = 0; /* True if subscription is wanted too */
15331534
if( !db_get_boolean("self-register", 0) ){
15341535
style_header("Registration not possible");
15351536
@ <p>This project does not allow user self-registration. Please contact the
15361537
@ project administrator to obtain an account.</p>
15371538
style_footer();
@@ -1542,10 +1543,11 @@
15421543
/* Prompt the user for email alerts if this repository is configured for
15431544
** email alerts and if the default permissions include "7" */
15441545
canDoAlerts = email_tables_exist() && db_int(0,
15451546
"SELECT fullcap(%Q) GLOB '*7*'", zPerms
15461547
);
1548
+ doAlerts = canDoAlerts && atoi(PD("alerts","1"))!=0;
15471549
15481550
zUserID = PDT("u","");
15491551
zPasswd = PDT("p","");
15501552
zConfirm = PDT("cp","");
15511553
zEAddr = PDT("ea","");
@@ -1580,13 +1582,22 @@
15801582
iErrLine = 5;
15811583
zErr = "Passwords do not match";
15821584
}else if( db_exists("SELECT 1 FROM user WHERE login=%Q", zUserID) ){
15831585
iErrLine = 1;
15841586
zErr = "This User ID is already taken. Choose something different.";
1585
- }else if( db_exists("SELECT 1 FROM user WHERE info LIKE '%%%q%%'", zEAddr) ){
1587
+ }else if(
1588
+ /* If the email is found anywhere in USER.INFO... */
1589
+ db_exists("SELECT 1 FROM user WHERE info LIKE '%%%q%%'", zEAddr)
1590
+ ||
1591
+ /* Or if the email is a verify subscriber email with an associated
1592
+ ** user... */
1593
+ db_exists(
1594
+ "SELECT 1 FROM subscriber WHERE semail=%Q AND suname IS NOT NULL"
1595
+ " AND sverified",zEAddr)
1596
+ ){
15861597
iErrLine = 3;
1587
- zErr = "This address is already used.";
1598
+ zErr = "This email address is already claimed by another user";
15881599
}else{
15891600
Blob sql;
15901601
int uid;
15911602
char *zPass = sha1_shared_secret(zPasswd, zUserID, 0);
15921603
blob_init(&sql, 0, 0);
@@ -1597,11 +1608,11 @@
15971608
zUserID, zPass, zPerms, zDName, zEAddr, g.zIpAddr);
15981609
fossil_free(zPass);
15991610
db_multi_exec("%s", blob_sql_text(&sql));
16001611
uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", zUserID);
16011612
login_set_user_cookie(zUserID, uid, NULL);
1602
- if( canDoAlerts && atoi(PD("alerts","1"))!=0 ){
1613
+ if( doAlerts ){
16031614
/* Also make the new user a subscriber. */
16041615
Blob hdr, body;
16051616
EmailSender *pSender;
16061617
sqlite3_int64 id; /* New subscriber Id */
16071618
const char *zCode; /* New subscriber code (in hex) */
@@ -1615,19 +1626,28 @@
16151626
if( g.perm.RdWiki ) ssub[nsub++] = 'w';
16161627
ssub[nsub] = 0;
16171628
db_multi_exec(
16181629
"INSERT INTO subscriber(semail,suname,"
16191630
" sverified,sdonotcall,sdigest,ssub,sctime,mtime,smip)"
1620
- "VALUES(%Q,%Q,%d,0,%d,%Q,now(),now(),%Q)",
1631
+ " VALUES(%Q,%Q,%d,0,%d,%Q,now(),now(),%Q)"
1632
+ " ON CONFLICT(semail) DO UPDATE"
1633
+ " SET suname=excluded.suname",
16211634
/* semail */ zEAddr,
16221635
/* suname */ zUserID,
16231636
/* sverified */ 0,
16241637
/* sdigest */ 0,
16251638
/* ssub */ ssub,
16261639
/* smip */ g.zIpAddr
16271640
);
16281641
id = db_last_insert_rowid();
1642
+ if( db_exists("SELECT 1 FROM subscriber WHERE semail=%Q"
1643
+ " AND sverified", zEAddr) ){
1644
+ /* This the case where the user was formerly a verified subscriber
1645
+ ** and here they have also registered as a user as well. It is
1646
+ ** not necessary to repeat the verfication step */
1647
+ redirect_to_g();
1648
+ }
16291649
zCode = db_text(0,
16301650
"SELECT hex(subscriberCode) FROM subscriber WHERE subscriberId=%lld",
16311651
id);
16321652
/* A verification email */
16331653
pSender = email_sender_new(0,0);
@@ -1706,10 +1726,12 @@
17061726
@ <tr>
17071727
@ <td class="form_label" align="right">Password:</td>
17081728
@ <td><input type="password" name="p" value="%h(zPasswd)" size="30"></td>
17091729
if( iErrLine==4 ){
17101730
@ <td><span class='loginError'>&larr; %h(zErr)</span></td>
1731
+ }else{
1732
+ @ <td>&larr; Must be at least 6 characters</td>
17111733
}
17121734
@ </tr>
17131735
@ <tr>
17141736
@ <td class="form_label" align="right">Confirm password:</td>
17151737
@ <td><input type="password" name="cp" value="%h(zConfirm)" size="30"></td>
17161738
--- src/login.c
+++ src/login.c
@@ -1528,10 +1528,11 @@
1528 char *zCaptcha;
1529 int iErrLine = -1;
1530 const char *zErr = 0;
1531 char *zPerms; /* Permissions for the default user */
1532 int canDoAlerts = 0; /* True if receiving email alerts is possible */
 
1533 if( !db_get_boolean("self-register", 0) ){
1534 style_header("Registration not possible");
1535 @ <p>This project does not allow user self-registration. Please contact the
1536 @ project administrator to obtain an account.</p>
1537 style_footer();
@@ -1542,10 +1543,11 @@
1542 /* Prompt the user for email alerts if this repository is configured for
1543 ** email alerts and if the default permissions include "7" */
1544 canDoAlerts = email_tables_exist() && db_int(0,
1545 "SELECT fullcap(%Q) GLOB '*7*'", zPerms
1546 );
 
1547
1548 zUserID = PDT("u","");
1549 zPasswd = PDT("p","");
1550 zConfirm = PDT("cp","");
1551 zEAddr = PDT("ea","");
@@ -1580,13 +1582,22 @@
1580 iErrLine = 5;
1581 zErr = "Passwords do not match";
1582 }else if( db_exists("SELECT 1 FROM user WHERE login=%Q", zUserID) ){
1583 iErrLine = 1;
1584 zErr = "This User ID is already taken. Choose something different.";
1585 }else if( db_exists("SELECT 1 FROM user WHERE info LIKE '%%%q%%'", zEAddr) ){
 
 
 
 
 
 
 
 
 
1586 iErrLine = 3;
1587 zErr = "This address is already used.";
1588 }else{
1589 Blob sql;
1590 int uid;
1591 char *zPass = sha1_shared_secret(zPasswd, zUserID, 0);
1592 blob_init(&sql, 0, 0);
@@ -1597,11 +1608,11 @@
1597 zUserID, zPass, zPerms, zDName, zEAddr, g.zIpAddr);
1598 fossil_free(zPass);
1599 db_multi_exec("%s", blob_sql_text(&sql));
1600 uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", zUserID);
1601 login_set_user_cookie(zUserID, uid, NULL);
1602 if( canDoAlerts && atoi(PD("alerts","1"))!=0 ){
1603 /* Also make the new user a subscriber. */
1604 Blob hdr, body;
1605 EmailSender *pSender;
1606 sqlite3_int64 id; /* New subscriber Id */
1607 const char *zCode; /* New subscriber code (in hex) */
@@ -1615,19 +1626,28 @@
1615 if( g.perm.RdWiki ) ssub[nsub++] = 'w';
1616 ssub[nsub] = 0;
1617 db_multi_exec(
1618 "INSERT INTO subscriber(semail,suname,"
1619 " sverified,sdonotcall,sdigest,ssub,sctime,mtime,smip)"
1620 "VALUES(%Q,%Q,%d,0,%d,%Q,now(),now(),%Q)",
 
 
1621 /* semail */ zEAddr,
1622 /* suname */ zUserID,
1623 /* sverified */ 0,
1624 /* sdigest */ 0,
1625 /* ssub */ ssub,
1626 /* smip */ g.zIpAddr
1627 );
1628 id = db_last_insert_rowid();
 
 
 
 
 
 
 
1629 zCode = db_text(0,
1630 "SELECT hex(subscriberCode) FROM subscriber WHERE subscriberId=%lld",
1631 id);
1632 /* A verification email */
1633 pSender = email_sender_new(0,0);
@@ -1706,10 +1726,12 @@
1706 @ <tr>
1707 @ <td class="form_label" align="right">Password:</td>
1708 @ <td><input type="password" name="p" value="%h(zPasswd)" size="30"></td>
1709 if( iErrLine==4 ){
1710 @ <td><span class='loginError'>&larr; %h(zErr)</span></td>
 
 
1711 }
1712 @ </tr>
1713 @ <tr>
1714 @ <td class="form_label" align="right">Confirm password:</td>
1715 @ <td><input type="password" name="cp" value="%h(zConfirm)" size="30"></td>
1716
--- src/login.c
+++ src/login.c
@@ -1528,10 +1528,11 @@
1528 char *zCaptcha;
1529 int iErrLine = -1;
1530 const char *zErr = 0;
1531 char *zPerms; /* Permissions for the default user */
1532 int canDoAlerts = 0; /* True if receiving email alerts is possible */
1533 int doAlerts = 0; /* True if subscription is wanted too */
1534 if( !db_get_boolean("self-register", 0) ){
1535 style_header("Registration not possible");
1536 @ <p>This project does not allow user self-registration. Please contact the
1537 @ project administrator to obtain an account.</p>
1538 style_footer();
@@ -1542,10 +1543,11 @@
1543 /* Prompt the user for email alerts if this repository is configured for
1544 ** email alerts and if the default permissions include "7" */
1545 canDoAlerts = email_tables_exist() && db_int(0,
1546 "SELECT fullcap(%Q) GLOB '*7*'", zPerms
1547 );
1548 doAlerts = canDoAlerts && atoi(PD("alerts","1"))!=0;
1549
1550 zUserID = PDT("u","");
1551 zPasswd = PDT("p","");
1552 zConfirm = PDT("cp","");
1553 zEAddr = PDT("ea","");
@@ -1580,13 +1582,22 @@
1582 iErrLine = 5;
1583 zErr = "Passwords do not match";
1584 }else if( db_exists("SELECT 1 FROM user WHERE login=%Q", zUserID) ){
1585 iErrLine = 1;
1586 zErr = "This User ID is already taken. Choose something different.";
1587 }else if(
1588 /* If the email is found anywhere in USER.INFO... */
1589 db_exists("SELECT 1 FROM user WHERE info LIKE '%%%q%%'", zEAddr)
1590 ||
1591 /* Or if the email is a verify subscriber email with an associated
1592 ** user... */
1593 db_exists(
1594 "SELECT 1 FROM subscriber WHERE semail=%Q AND suname IS NOT NULL"
1595 " AND sverified",zEAddr)
1596 ){
1597 iErrLine = 3;
1598 zErr = "This email address is already claimed by another user";
1599 }else{
1600 Blob sql;
1601 int uid;
1602 char *zPass = sha1_shared_secret(zPasswd, zUserID, 0);
1603 blob_init(&sql, 0, 0);
@@ -1597,11 +1608,11 @@
1608 zUserID, zPass, zPerms, zDName, zEAddr, g.zIpAddr);
1609 fossil_free(zPass);
1610 db_multi_exec("%s", blob_sql_text(&sql));
1611 uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", zUserID);
1612 login_set_user_cookie(zUserID, uid, NULL);
1613 if( doAlerts ){
1614 /* Also make the new user a subscriber. */
1615 Blob hdr, body;
1616 EmailSender *pSender;
1617 sqlite3_int64 id; /* New subscriber Id */
1618 const char *zCode; /* New subscriber code (in hex) */
@@ -1615,19 +1626,28 @@
1626 if( g.perm.RdWiki ) ssub[nsub++] = 'w';
1627 ssub[nsub] = 0;
1628 db_multi_exec(
1629 "INSERT INTO subscriber(semail,suname,"
1630 " sverified,sdonotcall,sdigest,ssub,sctime,mtime,smip)"
1631 " VALUES(%Q,%Q,%d,0,%d,%Q,now(),now(),%Q)"
1632 " ON CONFLICT(semail) DO UPDATE"
1633 " SET suname=excluded.suname",
1634 /* semail */ zEAddr,
1635 /* suname */ zUserID,
1636 /* sverified */ 0,
1637 /* sdigest */ 0,
1638 /* ssub */ ssub,
1639 /* smip */ g.zIpAddr
1640 );
1641 id = db_last_insert_rowid();
1642 if( db_exists("SELECT 1 FROM subscriber WHERE semail=%Q"
1643 " AND sverified", zEAddr) ){
1644 /* This the case where the user was formerly a verified subscriber
1645 ** and here they have also registered as a user as well. It is
1646 ** not necessary to repeat the verfication step */
1647 redirect_to_g();
1648 }
1649 zCode = db_text(0,
1650 "SELECT hex(subscriberCode) FROM subscriber WHERE subscriberId=%lld",
1651 id);
1652 /* A verification email */
1653 pSender = email_sender_new(0,0);
@@ -1706,10 +1726,12 @@
1726 @ <tr>
1727 @ <td class="form_label" align="right">Password:</td>
1728 @ <td><input type="password" name="p" value="%h(zPasswd)" size="30"></td>
1729 if( iErrLine==4 ){
1730 @ <td><span class='loginError'>&larr; %h(zErr)</span></td>
1731 }else{
1732 @ <td>&larr; Must be at least 6 characters</td>
1733 }
1734 @ </tr>
1735 @ <tr>
1736 @ <td class="form_label" align="right">Confirm password:</td>
1737 @ <td><input type="password" name="cp" value="%h(zConfirm)" size="30"></td>
1738

Keyboard Shortcuts

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