SnappOrder: register.php now needs birthdate

This commit is contained in:
nikolark committed 2014-06-17 20:27:51 +02:00
1 parent 967d814eda
commit a7e614a3d5
5 files changed
+18 -35

No files matched your search

-1
View File
@@ -121,7 +121,6 @@ if( isset($_POST['submit']) ) {
<!-- Account -->
<label for="id_username">Brukernavn:</label><input id="id_username" type="text" name="username" placeholder="Brukernavn" value="<?php echo $username; ?>" />
<label for="id_password">Passord:</label><input id="id_password" type="password" name="password" placeholder="Passord" value="<?php echo $password; ?>"/>
<label for="id_date_of_birth_day">Fødselsdato:</label><?php date_picker("id_date_of_birth"); ?>
<label for="id_place_of_study">Studiested:</label><?php institutions(); ?>
<label for="id_newsletter">Motta nyhetsbrev:</label><input type="checkbox" id="id_newsletter" name="newsletter" value="1"<?php echo $newsletter_checked; ?> /> Nyheter og kommende arrangementer på Studentersamfundet<br /><br />
<button type="submit" name="submit" class="btn-submit">Aktiver medlemskapet</button>
+1
View File
@@ -17,6 +17,7 @@
* "firstname": "Jon",
* "lastname": "Hansen",
* "email": "jon@uio.no",
* "birthdate": "1985-03-01",
* "registration_status": "partial" // "partial" means show link
* "registration_url": "/snapporder/register_partial.php?userid=4331&token=lol"
* }
+9 -1
View File
@@ -10,6 +10,7 @@
* "firstname": "Jon",
* "lastname": "Hansen",
* "email": "jon@uio.no",
* "birthdate": "1985-03-01" // format: ISO-8601 date
* "purchased": "2004-02-12" // optional, format: ISO-8601 date
* }
*
@@ -23,6 +24,7 @@
* "firstname": "Jon",
* "lastname": "Hansen",
* "email": "jon@uio.no",
* "birthdate": "1985-03-01",
* "registration_status": "partial" // "partial" means show link
* "registration_url": "/snapporder/register_partial.php?userid=4331&token=lol"
* }
@@ -62,7 +64,7 @@ if($data === NULL) {
}
/* Validate supplied data */
$required_keys = array('firstname', 'lastname', 'phone', 'email');
$required_keys = array('firstname', 'lastname', 'phone', 'email', 'birthdate');
$valid_keys = $required_keys;
$valid_keys[] = + 'purchased';
@@ -127,6 +129,12 @@ if( strlen($data['lastname']) < 2) {
echo json_encode(array('error' => 'Too short lastname: '.$data['lastname']));
die();
}
/* validate birthdate */
if( !valid_date($data['birthdate']) ) {
set_response_code(400);
echo json_encode(array('error' => 'Could not parse birthdate: \''.$data['birthdate'].'\''));
die();
}
/* Validate optional purchase_date */
if( isset($data['purchased']) ) {
+5 -31
View File
@@ -78,7 +78,7 @@ function get_user($user_id) {
* - a date >= NOW(): Valid membership
* - NULL: Lifelong membership
*/
$cols = array('id', 'firstname', 'lastname', 'email', 'expires', 'cardno', 'registration_status');
$cols = array('id', 'firstname', 'lastname', 'email', 'expires', 'cardno', 'registration_status', 'birthdate');
$sql_group_ids = "GROUP_CONCAT(group_id) AS group_ids";
$sql_is_member = "expires > NOW() OR expires IS NULL AS is_member";
$sql = "SELECT ".implode($cols, ",").",$sql_group_ids,$sql_is_member FROM din_user AS users LEFT JOIN din_usergrouprelationship AS ug ON users.id=ug.user_id WHERE users.id=$user_id GROUP BY users.id";
@@ -115,6 +115,9 @@ function get_user($user_id) {
unset($user['group_ids']);
$user['memberid'] = $user['id']; // rename
unset($user['id']);
if($user['birthdate'] == "0000-00-00") {
unset($user['birthdate']);
}
return $user;
}
@@ -310,15 +313,10 @@ function mailchimp_subscribe($data, $list_id, $api_key) {
function update_user($data) {
global $conn;
$birthdate_sql = "";
if( strlen($data['date_of_birth']) > 0) {
$birthdate_sql = "birthdate=" .$conn->quoteSmart($data['date_of_birth']).",";
}
// user: update existing user, activation_status="full", form data
$sql = "UPDATE din_user SET ";
$sql .= "username=" .$conn->quoteSmart($data['username']).",";
$sql .= "password=PASSWORD(" .$conn->quoteSmart($data['password'])."),";
$sql .= $birthdate_sql;
$sql .= "placeOfStudy=" .$conn->quoteSmart($data['place_of_study']).",";
$sql .= "registration_status='full'";
$sql .= " WHERE id = " . $conn->quoteSmart($data['userid']);
@@ -347,25 +345,8 @@ function update_user_groups($data) {
return true;
}
function validate_date_of_birth($data, $optional=true) {
$keys = array('year', 'month','day');
$values = array();
foreach( $keys as $key) {
// If started filling out date of birth
if(strlen($data[$key]) !== 0) {
$optional = false;
}
// year
$values[] = $data[$key];
}
if($optional) {
return ""; // skip
}
function valid_date($date) {
// try parsing
$date = implode('-', $values);
if(!clean_date($date)) {
return false;
}
@@ -395,13 +376,6 @@ function validate_activation_form($data) {
throw new ValidationException("Passordet kan ikke inneholde enkel- eller dobbelfnutt eller bakslask.");
}
// birthdate (optional)
$valid_date = validate_date_of_birth($data);
if( $valid_date === false ) {
throw new ValidationException("Ugyldig fødselsdato");
}
$data['date_of_birth'] = $valid_date; // Note: could be: ""
// place of study (optional)
if( !is_numeric($data['place_of_study']) ) {
throw new ValidationException("Ugyldig studiested");
+3 -2
View File
@@ -1,6 +1,7 @@
{
"firstname": "Test",
"lastname": "Testesen",
"email": "aaaadadfz@aaa222asd333a44zz.com",
"phone": "+4745115788"
"email": "aaaadadfz@aaa422asd333a44zz.com",
"birthdate": "1985-02-05",
"phone": "+4745115784"
}