Misc fixes, fixes normal registrations
This commit is contained in:
1 parent
8f1fa6dab5
commit
2e4e2a1ef9
9 files changed
+146
-14
No files matched your search
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
set_include_path("../includes/");
|
||||
require_once("../inside/credentials.php");
|
||||
require_once("../includes/DB.php");
|
||||
|
||||
/* Functions */
|
||||
|
||||
/* Set HTTP response code */
|
||||
function set_response_code($code) {
|
||||
if(!is_int($code)) {
|
||||
return false;
|
||||
}
|
||||
header('X-Ignore-This: something', true, $code);
|
||||
}
|
||||
|
||||
header('Access-Control-Allow-Origin: *', true); // Come fetch!
|
||||
|
||||
/* Connect to database */
|
||||
$options = array(
|
||||
'debug' => 2,
|
||||
'portability' => DB_PORTABILITY_ALL,
|
||||
);
|
||||
|
||||
$conn = DB::connect(getDSN(), $options);
|
||||
|
||||
if(DB :: isError($conn)) {
|
||||
echo $conn->toString();
|
||||
}
|
||||
$conn->setFetchMode(DB_FETCHMODE_ORDERED);
|
||||
|
||||
/* Validate params */
|
||||
if(!isset($_GET['q'])) {
|
||||
set_response_code(400);
|
||||
echo json_encode(array('error' => "Missing param q"));
|
||||
die();
|
||||
}
|
||||
|
||||
$query = $_GET['q'];
|
||||
$query = $conn->quoteSmart($query);
|
||||
|
||||
// Search query
|
||||
$sql = "SELECT id FROM din_user WHERE username=$query";
|
||||
$res = $conn->query($sql);
|
||||
|
||||
if( DB::isError($res) ) {
|
||||
set_response_code(500);
|
||||
echo json_encode(array('error' => $res->message));
|
||||
die();
|
||||
}
|
||||
$userExists = $res->numRows() > 0;
|
||||
|
||||
echo json_encode(array('result' => $userExists));
|
||||
|
||||
?>
|
||||
@@ -1694,7 +1694,7 @@ function validate_username_length($username) {
|
||||
return strlen(stripcslashes($username)) >= 3 && strlen(stripcslashes($username)) <= 12;
|
||||
}
|
||||
function validate_username_chars($username) {
|
||||
return preg_match('/^[a-z]+[a-z0-9]*$/', strtolower(stripcslashes($username)));
|
||||
return preg_match('/^[a-z][a-z0-9]*$/', strtolower(stripcslashes($username)));
|
||||
}
|
||||
function validate_password_length($password) {
|
||||
return strlen($password) >= 8;
|
||||
|
||||
@@ -110,6 +110,8 @@ if( isset($_POST['submit']) ) {
|
||||
<section class="activation">
|
||||
<?php if(strlen($validation_errors) > 0 ) {
|
||||
echo "<span class=\"error\">$validation_errors</span>";
|
||||
} else {
|
||||
echo "<span class=\"error hidden\"></span>";
|
||||
} ?>
|
||||
<form method="post" class="activation-form">
|
||||
<!-- Profile -->
|
||||
@@ -118,8 +120,8 @@ if( isset($_POST['submit']) ) {
|
||||
<input type="hidden" name="firstname" value="<?php echo $user['firstname']; ?>"/>
|
||||
<input type="hidden" name="lastname" value="<?php echo $user['lastname']; ?>"/>
|
||||
<!-- Account -->
|
||||
<div class="form-row">
|
||||
<label for="id_username">Brukernavn:</label><input id="id_username" type="text" name="username" placeholder="Brukernavn" value="<?php echo $username; ?>" />
|
||||
<div class="form-row username-row">
|
||||
<label for="id_username">Brukernavn:</label><input id="id_username" type="text" name="username" placeholder="Brukernavn" value="<?php echo $username; ?>" maxlength="12"/><div class="username-check"></div>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="id_password">Passord:</label><input id="id_password" type="password" name="password" placeholder="Passord" value="<?php echo $password; ?>"/>
|
||||
|
||||
@@ -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;-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
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 31 KiB |
@@ -3,18 +3,58 @@
|
||||
function lookup_area(query) {
|
||||
var area = $('.area-wrap');
|
||||
$.getJSON('/api/zipcode.php', {q: query}, function(data) {
|
||||
console.log(data);
|
||||
area.html(data.result);
|
||||
});
|
||||
}
|
||||
function validate_username(query) {
|
||||
var check = $('.username-check');
|
||||
var error_msg = $(".activation > .error");
|
||||
var valid_chars_pattern = new RegExp('^[a-z][a-z0-9]*');
|
||||
if(query.length == 0) {
|
||||
error_msg.html('');
|
||||
check.removeClass("failed");
|
||||
check.removeClass("check");
|
||||
error_msg.addClass("hidden");
|
||||
return;
|
||||
}
|
||||
if( !valid_chars_pattern.test(query) ) {
|
||||
error_msg.html('Brukernavnet kan kun inneholde små bokstaver og tall (tall kan ikke være første tegn)');
|
||||
check.removeClass("failed");
|
||||
check.removeClass("check");
|
||||
error_msg.removeClass("hidden");
|
||||
return;
|
||||
}
|
||||
$.getJSON('/api/username.php', {q: query}, function(data) {
|
||||
console.log(data);
|
||||
if(data.result) {
|
||||
error_msg.html('Brukernavnet er desverre opptatt, prøv en annen variant');
|
||||
check.addClass("failed");
|
||||
check.removeClass("check");
|
||||
error_msg.removeClass("hidden");
|
||||
} else {
|
||||
check.addClass("check");
|
||||
check.removeClass("failed");
|
||||
error_msg.addClass("hidden");
|
||||
error_msg.html('');
|
||||
}
|
||||
});
|
||||
}
|
||||
$(document).ready(function() {
|
||||
var zipcode_field = $('input[name=zipcode]');
|
||||
var username_field= $('input[name=username]');
|
||||
|
||||
if(zipcode_field.val().length !== 0) {
|
||||
lookup_area(zipcode_field.val());
|
||||
}
|
||||
|
||||
zipcode_field.on('keyup', function(event) {
|
||||
zipcode_field.on('keyup keypress', function(event) {
|
||||
var query = event.target.value;
|
||||
lookup_area(query);
|
||||
});
|
||||
|
||||
username_field.on('keyup keypress', function(event) {
|
||||
var query = event.target.value;
|
||||
validate_username(query);
|
||||
});
|
||||
|
||||
});
|
||||
@@ -22,12 +22,14 @@ function add_user($data) {
|
||||
/* User table */
|
||||
$phone = $data['phone']; // used later
|
||||
unset($data['phone']);
|
||||
unset($data['user_id']);
|
||||
|
||||
/* Add our own initial values */
|
||||
$data['username'] = generate_username($data);
|
||||
$data['source'] = "snapporder";
|
||||
$data['registration_status'] = "partial";
|
||||
|
||||
|
||||
/* Membership expiry */
|
||||
/* One year from today (default) */
|
||||
if( !isset($data['purchased']) ) {
|
||||
@@ -47,7 +49,7 @@ function add_user($data) {
|
||||
$res = $conn->execute($sth, $values);
|
||||
|
||||
if( DB::isError($res) ) {
|
||||
throw new InsideDatabaseException($res->getMessage());
|
||||
throw new InsideDatabaseException($res->getMessage().". DEBUG: ".$res->getDebugInfo());
|
||||
}
|
||||
|
||||
$user_id = get_user_id_by_username($data['username']);
|
||||
@@ -60,7 +62,7 @@ function add_user($data) {
|
||||
$res = $conn->execute($sth, $values);
|
||||
|
||||
if( DB::isError($res) ) {
|
||||
throw new InsideDatabaseException($res->getMessage());
|
||||
throw new InsideDatabaseException($res->getMessage().". DEBUG: ".$res->getDebugInfo());
|
||||
}
|
||||
|
||||
log_userupdate($user_id, "User registered."); // for legacy
|
||||
@@ -85,7 +87,7 @@ function get_user($user_id) {
|
||||
$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";
|
||||
$res = $conn->query($sql);
|
||||
if( DB::isError($res) ) {
|
||||
throw new InsideDatabaseException($res->getMessage());
|
||||
throw new InsideDatabaseException($res->getMessage().". DEBUG: ".$res->getDebugInfo());
|
||||
}
|
||||
if($res->numRows() === 0) {
|
||||
return false;
|
||||
@@ -184,7 +186,7 @@ function get_user_id_by_username($username) {
|
||||
$sql = "SELECT id FROM din_user WHERE username='$username'";
|
||||
$res = $conn->query($sql);
|
||||
if( DB::isError($res) ) {
|
||||
throw new InsideDatabaseException($res->getMessage());
|
||||
throw new InsideDatabaseException($res->getMessage().". DEBUG: ".$res->getDebugInfo());
|
||||
}
|
||||
if( $res->numRows() === 0 ) {
|
||||
return false;
|
||||
@@ -291,7 +293,7 @@ function institutions($output=true) {
|
||||
$sql = "SELECT * FROM studiesteder";
|
||||
$res = $conn->getAll($sql);
|
||||
if( DB::isError($res) ) {
|
||||
throw new InsideDatabaseException($res->getMessage());
|
||||
throw new InsideDatabaseException($res->getMessage().". DEBUG: ".$res->getDebugInfo());
|
||||
}
|
||||
$institutions = $res;
|
||||
|
||||
@@ -370,6 +372,7 @@ function update_user($data) {
|
||||
// user: update existing user, activation_status="full", form data
|
||||
$sql = "UPDATE din_user SET ";
|
||||
$sql .= "username=" .$conn->quoteSmart($data['username']).",";
|
||||
$sql .= "ldap_username=" .$conn->quoteSmart($data['username']).",";
|
||||
$sql .= "password=PASSWORD(" .$conn->quoteSmart($data['password'])."),";
|
||||
$sql .= $birthdate_sql;
|
||||
$sql .= "placeOfStudy=" .$conn->quoteSmart($data['place_of_study']).",";
|
||||
@@ -378,7 +381,7 @@ function update_user($data) {
|
||||
$res = $conn->query($sql);
|
||||
|
||||
if (DB::isError($res)) {
|
||||
throw new InsideDatabaseException($res->getMessage());
|
||||
throw new InsideDatabaseException($res->getMessage().". DEBUG: ".$res->getDebugInfo());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -448,12 +451,12 @@ function validate_birthdate($data, $optional=true) {
|
||||
function validate_activation_form($data) {
|
||||
|
||||
// username: length, ascii, exists
|
||||
$data['username'] = trim($data['username']);
|
||||
$data['username'] = strtolower(trim($data['username']));
|
||||
if( !validate_username_length($data['username']) ) {
|
||||
throw new ValidationException("Brukernavet må være mellom 3 og 12 tegn");
|
||||
}
|
||||
if( !validate_username_chars($data['username']) ) {
|
||||
throw new ValidationException("Brukernavnet kan kun inneholde små bokstaver.");
|
||||
throw new ValidationException("Brukernavnet kan kun inneholde små bokstaver og tall (tall kan ikke være første tegn).");
|
||||
}
|
||||
if( get_user_id_by_username($data['username'], false) !== false) {
|
||||
throw new ValidationException("Brukernavnet er allerede i bruk.");
|
||||
|
||||
@@ -73,6 +73,10 @@ body {
|
||||
|
||||
span.error {
|
||||
margin-bottom: 0;
|
||||
|
||||
&.hidden {
|
||||
display: none !important;
|
||||
}
|
||||
}
|
||||
|
||||
.activation-form {
|
||||
@@ -140,6 +144,35 @@ body {
|
||||
margin-right: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
.username-row {
|
||||
position: relative;
|
||||
}
|
||||
input[name=username] {
|
||||
}
|
||||
.username-check {
|
||||
position: absolute;
|
||||
pointer-events: none;
|
||||
right: 0;
|
||||
top: 0;
|
||||
width: 46px;
|
||||
height: 46px;
|
||||
z-index: 4;
|
||||
background-image: url('../img/icon-check.png');
|
||||
background-size: 50% 50%;
|
||||
background-position: center center;
|
||||
background-repeat: no-repeat;
|
||||
visibility: hidden;
|
||||
|
||||
&.check {
|
||||
background-image: url('../img/icon-check.png');
|
||||
visibility: visible;
|
||||
}
|
||||
&.failed {
|
||||
background-image: url('../img/icon-failed.png');
|
||||
visibility: visible;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.btn-submit {
|
||||
|
||||
Reference in new issue
Block a user