Working SMS activation form

This commit is contained in:
nikolark committed 2014-08-11 15:50:16 +02:00
1 parent 929a64e428
commit 9c85464303
6 files changed
+69 -39

No files matched your search

+5
View File
@@ -1720,6 +1720,11 @@ function clean_date($date) {
// returns a DateTime object
return date_create_from_format('Y-m-d', $date);
}
// MySQL TIMESTAMP Y-m-d H:i:s
function clean_timestamp($date) {
// returns a DateTime object
return date_create_from_format('Y-m-d H:i:s', $date);
}
// E.164
function valid_phonenumber($phone) {
return preg_match('/^\+?\d{8,15}$/i', $phone);
+12 -14
View File
@@ -1,13 +1,11 @@
<?php
/* SMS purchase activation form
*
* TODO possible to activate expired memberships?
*/
set_include_path("../includes/");
require_once("../inside/credentials.php");
require_once("../inside/functions.php");
require_once("../inside/migration/ldap_api_functions.php");
require_once("DB.php");
require_once("../snapporder/lib/functions.php");
@@ -26,7 +24,7 @@ if(DB :: isError($conn)) {
$conn->setFetchMode(DB_FETCHMODE_ASSOC);
// empty default form values
$validation_errors = "";
$firstname = "";
$lastname = "";
$email = "";
@@ -51,6 +49,8 @@ if( isset($_POST['submit']) ) {
$validation_errors = $e->getMessage();
/* Refill form values*/
$phone = $_POST['phone'];
$activation_code = $_POST['activation_code'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
@@ -58,17 +58,15 @@ if( isset($_POST['submit']) ) {
if($data !== NULL) {
try {
// persist
save_sms_form($data);
$user_id = save_sms_form($data);
$user = get_user($user_id);
$user = get_user($data['userid']);
// send email about user registration (same as on new snapporder membership)
$user['registration_url'] = generate_registration_url($user, SECRET_KEY);
send_activation_email($data, $user);
// send warm and fuzzy welcome email
send_registration_email($data); // same as on new snapporder membership
$url = $data['registration_url'];
// redirect to confirmation page
redirect("/snapporder/$url");
// redirect to second form
header("Location: ".$user['registration_url']);
die();
} catch(InsideDatabaseException $e) {
echo $e->getMessage();
@@ -97,7 +95,7 @@ if( isset($_POST['submit']) ) {
<div class="activation-form">
<!-- Profile -->
<div class="form-row">
<label for="id_phone">Telefonnummer:</label><input id="id_phone" type="text" name="phone" placeholder="Telefonnummer" value="<?php echo $phone; ?>"/>
<label for="id_phone">Telefonnummer:</label><input id="id_phone" type="tel" name="phone" placeholder="Telefonnummer" value="<?php echo $phone; ?>"/>
</div>
<div class="form-row">
<label for="id_activation_code">Aktiveringskode:</label><input id="id_activation_code" type="text" name="activation_code" placeholder="Aktiveringskode" value="<?php echo $activation_code; ?>"/>
@@ -109,7 +107,7 @@ if( isset($_POST['submit']) ) {
<label for="id_lastname">Etternavn:</label><input id="id_lastname" type="text" name="lastname" placeholder="Etternavn" value="<?php echo $lastname; ?>"/>
</div>
<div class="form-row">
<label for="id_email">Epost:</label><input id="id_email" type="email" name="email" placeholder="Passord" value="<?php echo $email; ?>"/>
<label for="id_email">Epost:</label><input id="id_email" type="email" name="email" placeholder="Epost" value="<?php echo $email; ?>"/>
</div>
<button type="submit" name="submit" class="btn-submit">Registrer medlemskapet mitt</button>
+1 -1
View File
@@ -194,7 +194,7 @@ if( isset($data['membership_trial']) && $data['membership_trial'] !== "buddy") {
/* Create user */
try {
if( $reg_type === "new" ) {
$user_id = add_user($data);
$user_id = add_user($data, "snapporder");
} else {
renew_user($data);
}
+1 -1
View File
@@ -1 +1 @@
/*! normalize.css v3.0.1 | MIT License | git.io/normalize */html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;}body{margin:0;}article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block;}audio,canvas,progress,video{display:inline-block;vertical-align:baseline;}audio:not([controls]){display:none;height:0;}[hidden],template{display:none;}a{background:transparent;}a:active,a:hover{outline:0;}abbr[title]{border-bottom:1px dotted;}b,strong{font-weight:bold;}dfn{font-style:italic;}h1{font-size:2em;margin:0.67em 0;}mark{background:#ff0;color:#000;}small{font-size:80%;}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline;}sup{top:-0.5em;}sub{bottom:-0.25em;}img{border:0;}svg:not(:root){overflow:hidden;}figure{margin:1em 40px;}hr{-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box;height:0;}pre{overflow:auto;}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em;}button,input,optgroup,select,textarea{color:inherit;font:inherit;margin:0;}button{overflow:visible;}button,select{text-transform:none;}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer;}button[disabled],html input[disabled]{cursor:default;}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0;}input{line-height:normal;}input[type="checkbox"],input[type="radio"]{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;padding:0;}input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button{height:auto;}input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box;}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none;}fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:0.35em 0.625em 0.75em;}legend{border:0;padding:0;}textarea{overflow:auto;}optgroup{font-weight:bold;}table{border-collapse:collapse;border-spacing:0;}td,th{padding:0;}meta.foundation-version{font-family:"/5.2.3/";}meta.foundation-mq-small{font-family:"/only screen/";width:0em;}meta.foundation-mq-medium{font-family:"/only screen and (min-width:40.063em)/";width:40.063em;}meta.foundation-mq-large{font-family:"/only screen and (min-width:64.063em)/";width:64.063em;}meta.foundation-mq-xlarge{font-family:"/only screen and (min-width:90.063em)/";width:90.063em;}meta.foundation-mq-xxlarge{font-family:"/only screen and (min-width:120.063em)/";width:120.063em;}meta.foundation-data-attribute-namespace{font-family:false;}html,body{height:100%;}*,*:before,*:after{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;}html,body{font-size:100%;}body{background:#fff;color:#222;padding:0;margin:0;font-family:"Helvetica Neue","Helvetica",Helvetica,Arial,sans-serif;font-weight:normal;font-style:normal;line-height:1;position:relative;cursor:default;}a:hover{cursor:pointer;}img{max-width:100%;height:auto;}img{-ms-interpolation-mode:bicubic;}#map_canvas img,#map_canvas embed,#map_canvas object,.map_canvas img,.map_canvas embed,.map_canvas object{max-width:none !important;}.left{float:left !important;}.right{float:right !important;}.clearfix:before,.clearfix:after{content:" ";display:table;}.clearfix:after{clear:both;}.hide{display:none;}.antialiased{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;}img{display:inline-block;vertical-align:middle;}textarea{height:auto;min-height:50px;}select{width:100%;}.row{width:100%;margin-left:auto;margin-right:auto;margin-top:0;margin-bottom:0;max-width:62.5rem;}.row:before,.row:after{content:" ";display:table;}.row:after{clear:both;}.row.collapse>.column,.row.collapse>.columns{padding-left:0;padding-right:0;}.row.collapse .row{margin-left:0;margin-right:0;}.row .row{width:auto;margin-left:-0.9375rem;margin-right:-0.9375rem;margin-top:0;margin-bottom:0;max-width:none;}.row .row:before,.row .row:after{content:" ";display:table;}.row .row:after{clear:both;}.row .row.collapse{width:auto;margin:0;max-width:none;}.row .row.collapse:before,.row .row.collapse:after{content:" ";display:table;}.row .row.collapse:after{clear:both;}.column,.columns{padding-left:0.9375rem;padding-right:0.9375rem;width:100%;float:left;}@media only screen{.small-push-0{position:relative;left:0%;right:auto;}.small-pull-0{position:relative;right:0%;left:auto;}.small-push-1{position:relative;left:8.3333333333%;right:auto;}.small-pull-1{position:relative;right:8.3333333333%;left:auto;}.small-push-2{position:relative;left:16.6666666667%;right:auto;}.small-pull-2{position:relative;right:16.6666666667%;left:auto;}.small-push-3{position:relative;left:25%;right:auto;}.small-pull-3{position:relative;right:25%;left:auto;}.small-push-4{position:relative;left:33.3333333333%;right:auto;}.small-pull-4{position:relative;right:33.3333333333%;left:auto;}.small-push-5{positLine truncated
/*! normalize.css v3.0.1 | MIT License | git.io/normalize */html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;}body{margin:0;}article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block;}audio,canvas,progress,video{display:inline-block;vertical-align:baseline;}audio:not([controls]){display:none;height:0;}[hidden],template{display:none;}a{background:transparent;}a:active,a:hover{outline:0;}abbr[title]{border-bottom:1px dotted;}b,strong{font-weight:bold;}dfn{font-style:italic;}h1{font-size:2em;margin:0.67em 0;}mark{background:#ff0;color:#000;}small{font-size:80%;}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline;}sup{top:-0.5em;}sub{bottom:-0.25em;}img{border:0;}svg:not(:root){overflow:hidden;}figure{margin:1em 40px;}hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0;}pre{overflow:auto;}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em;}button,input,optgroup,select,textarea{color:inherit;font:inherit;margin:0;}button{overflow:visible;}button,select{text-transform:none;}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer;}button[disabled],html input[disabled]{cursor:default;}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0;}input{line-height:normal;}input[type="checkbox"],input[type="radio"]{-moz-box-sizing:border-box;box-sizing:border-box;padding:0;}input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button{height:auto;}input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;box-sizing:content-box;}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none;}fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:0.35em 0.625em 0.75em;}legend{border:0;padding:0;}textarea{overflow:auto;}optgroup{font-weight:bold;}table{border-collapse:collapse;border-spacing:0;}td,th{padding:0;}meta.foundation-version{font-family:"/5.2.3/";}meta.foundation-mq-small{font-family:"/only screen/";width:0em;}meta.foundation-mq-medium{font-family:"/only screen and (min-width:40.063em)/";width:40.063em;}meta.foundation-mq-large{font-family:"/only screen and (min-width:64.063em)/";width:64.063em;}meta.foundation-mq-xlarge{font-family:"/only screen and (min-width:90.063em)/";width:90.063em;}meta.foundation-mq-xxlarge{font-family:"/only screen and (min-width:120.063em)/";width:120.063em;}meta.foundation-data-attribute-namespace{font-family:false;}html,body{height:100%;}*,*:before,*:after{-moz-box-sizing:border-box;box-sizing:border-box;}html,body{font-size:100%;}body{background:#fff;color:#222;padding:0;margin:0;font-family:"Helvetica Neue","Helvetica",Helvetica,Arial,sans-serif;font-weight:normal;font-style:normal;line-height:1;position:relative;cursor:default;}a:hover{cursor:pointer;}img{max-width:100%;height:auto;}img{-ms-interpolation-mode:bicubic;}#map_canvas img,#map_canvas embed,#map_canvas object,.map_canvas img,.map_canvas embed,.map_canvas object{max-width:none !important;}.left{float:left !important;}.right{float:right !important;}.clearfix:before,.clearfix:after{content:" ";display:table;}.clearfix:after{clear:both;}.hide{display:none;}.antialiased{-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;}img{display:inline-block;vertical-align:middle;}textarea{height:auto;min-height:50px;}select{width:100%;}.row{width:100%;margin-left:auto;margin-right:auto;margin-top:0;margin-bottom:0;max-width:62.5rem;}.row:before,.row:after{content:" ";display:table;}.row:after{clear:both;}.row.collapse>.column,.row.collapse>.columns{padding-left:0;padding-right:0;}.row.collapse .row{margin-left:0;margin-right:0;}.row .row{width:auto;margin-left:-0.9375rem;margin-right:-0.9375rem;margin-top:0;margin-bottom:0;max-width:none;}.row .row:before,.row .row:after{content:" ";display:table;}.row .row:after{clear:both;}.row .row.collapse{width:auto;margin:0;max-width:none;}.row .row.collapse:before,.row .row.collapse:after{content:" ";display:table;}.row .row.collapse:after{clear:both;}.column,.columns{padding-left:0.9375rem;padding-right:0.9375rem;width:100%;float:left;}@media only screen{.small-push-0{position:relative;left:0%;right:auto;}.small-pull-0{position:relative;right:0%;left:auto;}.small-push-1{position:relative;left:8.3333333333%;right:auto;}.small-pull-1{position:relative;right:8.3333333333%;left:auto;}.small-push-2{position:relative;left:16.6666666667%;right:auto;}.small-pull-2{position:relative;right:16.6666666667%;left:auto;}.small-push-3{position:relative;left:25%;right:auto;}.small-pull-3{position:relative;right:25%;left:auto;}.small-push-4{position:relative;left:33.3333333333%;right:auto;}.small-pull-4{position:relative;right:33.3333333333%;left:auto;}.small-push-5{position:relative;left:41.6666666667%;right:auto;}.small-pull-5{position:relative;right:41.6666666667%;left:auto;}.small-push-6Line truncated
+49 -23
View File
@@ -362,7 +362,6 @@ function mailchimp_subscribe($data, $list_id, $api_key) {
'double_optin' => false,
'update_existing' => true, // if email exists, dont throw an error
'send_welcome' => false
);
$payload = json_encode($data);
@@ -516,27 +515,51 @@ function validate_activation_form($data) {
return $data;
}
function validate_sms_form($data) {
// lookup phonenumber
$data['phone'] = clean_phonenumber($data['phone']);
if( !valid_phonenumber($data['phone']) ) {
throw new ValidationException("Ugyldig telefonnummer");
}
$user_id = getUseridFromPhone($data['phone']);
if( $user_id !== false ) {
throw new ValidationException("Telefonnummeret er allerede registrert i bruk.");
function validate_sms_form($data) {
// phonenumber
$phone = clean_phonenumber($data['phone']);
if( !valid_phonenumber($phone) ) {
throw new ValidationException("Ugyldig telefonnummer: ".$data['phone']);
}
// lookup code and phonenumber tuple
$phone = substr($data['phone'], 0, 3);
// TODO: you are here
// get purchased from date
if( getUseridFromPhone($phone) !== false ) {
throw new ValidationException("Telefonnummeret ".$data['phone']." er allerede registrert i bruk.");
}
$data['phone'] = $phone;
// lookup code and phonenumber tuple to validate code and get purchase date
$purchased = get_purchase_date($data['phone'], $data['activation_code']);
if( $purchased === false ) {
throw new ValidationException("Ugyldig aktiveringskode ".$data['activation_code']);
}
$data['purchased'] = clean_timestamp($purchased);
/* validate firstname and lastname */
if( strlen($data['firstname']) < 2 ) {
throw new ValidationException("Fornavn må være 2 tegn eller lengre: ".$data['firstname']);
}
if( strlen($data['lastname']) < 2 ) {
throw new ValidationException("Etternavn må være 2 tegn eller lengre: ".$data['lastname']);
}
// email
if( !valid_email($data['email']) ) {
throw new ValidationException("Ugyldig epost: ".$data['email']);
}
if( getUseridFromEmail($data['email']) !== false ) {
throw new ValidationException("Epostadressen ".$data['email']." er allerede registrert i bruk");
}
// remove fields for later db insertion
unset($data['activation_code']);
unset($data['submit']);
return $data;
}
function save_sms_form($data) {
add_user($data, "sms");
$user_id = add_user($data, "sms");
log_userupdate($user_id, "Membership activated.");
return $user_id;
}
function save_activation_form($data) {
update_user($data);
@@ -554,15 +577,18 @@ function save_activation_form($data) {
return true;
}
function is_valid_sms_activation_code($phone, $code) {
$sql = "SELECT * FROM din_sms_sent AS s WHERE s.activation_code=$code AND s.reciever=$phone";
$res = $conn->query($sql);
function get_purchase_date($phone, $activation_code) {
global $conn;
$gsm = substr($phone, 3); // strip off country code
$sql = "SELECT date FROM din_sms_sent AS s WHERE s.activation_code=".$conn->quoteSmart($activation_code)." AND s.receiver=".$conn->quoteSmart($gsm);
$res = $conn->getOne($sql);
if( DB::isError($res) ) {
throw new InsideDatabaseException($res->getMessage().". DEBUG: ".$res->getDebugInfo());
}
if($res->numRows() === 0) {
return false;
}
return $res !== null ? $res : false;
}
/* The purpose of this email is:
@@ -581,7 +607,7 @@ function send_activation_email($data, $user) {
$message = '<html><body>';
$message .= '<h3>Hei '.$user['firstname'].', og velkommen til Det Norske Studentersamfund!</h3>';
$message .= '<p>For at medlemskapet ditt skal v&aelig;re gyldig trenger vi noen flere opplysninger fra deg.</p>';
$message .= '<p>For at medlemskapet ditt skal v&aelig;re komplett trenger vi noen flere opplysninger fra deg.</p>';
$message .= '<p style="margin-bottom: 20px;">Trykk p&aring; lenken under for &aring; fortsette.</p>';
$message .= '<p style="margin-bottom: 20px;"><a href="'.$user['registration_url'].'" style="font-family: Arial,sans-serif; color: white; font-weight: bold; font-size: 20px; padding: 0.8em 1.2em; border: none; text-decoration: none; background-color: #58AA58; display: inline-block; text-align: center; margin: 0;">Aktiver medlemskapet</a></p>';
$message .= "<p>Med vennlig hilsen<br>Det Norske Studentersamfund</p>";
+1
View File
@@ -100,6 +100,7 @@ span.error {
}
input[type=text],
input[type=email],
input[type=tel],
input[type=password] {
display: inline-block;
width: 70%;