Fossil

Diff
Login

Diff

Differences From Artifact [b31088a921]:

To Artifact [4d8632fa58]:


634
635
636
637
638
639
640



641
642
643
644
645
646
647
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650







+
+
+







** WEBPAGE: register
**
** Generate the register page.
**
*/
void register_page(void){
  const char *zUsername, *zPasswd, *zConfirm, *zContact, *zCS, *zPw, *zCap;
  unsigned int uSeed;
  char const *zDecoded;
  char *zCaptcha;
  if( !db_get_boolean("self-register", 0) ){
    style_header("Registration not possible");
    @ <p>This project does not allow user self-registration. Please contact the
    @ project administrator to obtain an account.</p>
    style_footer();
    return;
  }
687
688
689
690
691
692
693






694
695
696
697
698
699
700
701
702

703
704
705
706
707




708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725



726
727
728
729
730
731
732
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710

711





712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730



731
732
733
734
735
736
737
738
739
740







+
+
+
+
+
+








-
+
-
-
-
-
-
+
+
+
+















-
-
-
+
+
+







        /* Here lies the reason I don't use zErrMsg - it would not substitute
         * this %s(zUsername), or at least I don't know how to force it to.*/
        @ <p><span class="loginError">
        @ %s(zUsername) already exists.
        @ </span></p>
      }else{
        char *zPw = sha1_shared_secret(blob_str(&passwd), blob_str(&login));
        int uid;
        char *zCookie;
        const char *zCookieName;
        const char *zExpire;
        int expires;
        const char *zIpAddr;
        db_multi_exec(
            "INSERT INTO user(login,pw,cap,info)"
            "VALUES(%B,%Q,%B,%B)",
            &login, zPw, &caps, &contact
            );
        free(zPw);

        /* The user is registered, now just log him in. */
        int uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", zUsername);
        uid = db_int(0, "SELECT uid FROM user WHERE login=%Q", zUsername);
        char *zCookie;
        const char *zCookieName = login_cookie_name();
        const char *zExpire = db_get("cookie-expire","8766");
        int expires = atoi(zExpire)*3600;
        const char *zIpAddr = PD("REMOTE_ADDR","nil");
        zCookieName = login_cookie_name();
        zExpire = db_get("cookie-expire","8766");
        expires = atoi(zExpire)*3600;
        zIpAddr = PD("REMOTE_ADDR","nil");

        zCookie = db_text(0, "SELECT '%d/' || hex(randomblob(25))", uid);
        cgi_set_cookie(zCookieName, zCookie, 0, expires);
        db_multi_exec(
            "UPDATE user SET cookie=%Q, ipaddr=%Q, "
            "  cexpire=julianday('now')+%d/86400.0 WHERE uid=%d",
            zCookie, zIpAddr, expires, uid
            );
        redirect_to_g();

      }
    }
  }

  /* Prepare the captcha. */
  unsigned int uSeed = captcha_seed();
  char const *zDecoded = captcha_decode(uSeed);
  char *zCaptcha = captcha_render(zDecoded);
  uSeed = captcha_seed();
  zDecoded = captcha_decode(uSeed);
  zCaptcha = captcha_render(zDecoded);

  /* Print out the registration form. */
  @ <form action="register" method="post">
  if( P("g") ){
    @ <input type="hidden" name="g" value="%h(P("g"))" />
  }
  @ <p><input type="hidden" name="cs" value="%u(uSeed)" />