Implemented picking users based on email on the checkout page
This commit is contained in:
parent
dbdceadb5e
commit
cb4a3b131a
@ -534,12 +534,22 @@
|
|||||||
list="user_suggest"
|
list="user_suggest"
|
||||||
autocomplete="off"
|
autocomplete="off"
|
||||||
placeholder="Användarnamn"
|
placeholder="Användarnamn"
|
||||||
value="¤user¤"
|
value="¤user¤" />
|
||||||
required />
|
|
||||||
<button type="submit" >
|
<button type="submit" >
|
||||||
Välj
|
Välj
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<label for="email">
|
||||||
|
E-post:
|
||||||
|
</label>
|
||||||
|
<input type="text"
|
||||||
|
name="email"
|
||||||
|
id="email"
|
||||||
|
autocomplete="off"
|
||||||
|
placeholder="E-post"
|
||||||
|
value="¤email¤" />
|
||||||
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label for="displayname">
|
<label for="displayname">
|
||||||
Namn:
|
Namn:
|
||||||
|
@ -1,30 +1,68 @@
|
|||||||
<?php
|
<?php
|
||||||
class CheckoutPage extends Page {
|
class CheckoutPage extends Page {
|
||||||
private $userstr = '';
|
private $userstr = '';
|
||||||
|
private $emailstr = '';
|
||||||
private $user = null;
|
private $user = null;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
if(isset($_GET['user'])) {
|
if(isset($_GET['user'])) {
|
||||||
$this->userstr = trim(strtolower($_GET['user']));
|
$this->userstr = trim(strtolower($_GET['user']));
|
||||||
|
}
|
||||||
|
if(isset($_GET['email'])) {
|
||||||
|
$this->emailstr = trim(strtolower($_GET['email']));
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
$this->user = $this->user_init($this->userstr,
|
||||||
|
$this->emailstr);
|
||||||
|
} catch(Exception $e) {
|
||||||
|
$this->error = $e->getMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function user_init($name, $email) {
|
||||||
|
$nameuser = null;
|
||||||
|
$emailuser = null;
|
||||||
|
if($name) {
|
||||||
try {
|
try {
|
||||||
$this->user = new User($this->userstr, 'name');
|
$nameuser = new User($this->userstr, 'name');
|
||||||
} catch(Exception $ue) {
|
} catch(Exception $ue) {
|
||||||
|
# The user wasn't found locally
|
||||||
try {
|
try {
|
||||||
$ldap = new Ldap();
|
$this->ldap->get_user($this->userstr);
|
||||||
$ldap->get_user($this->userstr);
|
$nameuser = User::create_user($this->userstr);
|
||||||
$this->user = User::create_user($this->userstr);
|
|
||||||
} catch(Exception $le) {
|
} catch(Exception $le) {
|
||||||
$this->error = "Användarnamnet '";
|
$err = "Användarnamnet '$name' kunde inte hittas.";
|
||||||
$this->error .= $this->userstr;
|
throw new Exception($err);
|
||||||
$this->error .= "' kunde inte hittas.";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if($email) {
|
||||||
|
try {
|
||||||
|
# Lookup email directly in ldap since we don't store it
|
||||||
|
$emailuser = new User($this->ldap->search_email($email),
|
||||||
|
'name');
|
||||||
|
} catch(Exception $ue) {
|
||||||
|
$err = "E-postadressen '$emailuser' kunde inte hittas.";
|
||||||
|
throw new Exception($err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if($nameuser && $emailuser) {
|
||||||
|
if($nameuser != $emailuser) {
|
||||||
|
$err = "Användarnamn och e-post matchar olika användare.";
|
||||||
|
throw new Exception($err);
|
||||||
|
}
|
||||||
|
return $nameuser;
|
||||||
|
}
|
||||||
|
if($nameuser) {
|
||||||
|
return $nameuser;
|
||||||
|
}
|
||||||
|
return $emailuser;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function render_body() {
|
protected function render_body() {
|
||||||
$username = '';
|
$username = '';
|
||||||
|
$email = '';
|
||||||
$displayname = '';
|
$displayname = '';
|
||||||
$notes = '';
|
$notes = '';
|
||||||
$loan_table = '';
|
$loan_table = '';
|
||||||
@ -33,6 +71,7 @@ class CheckoutPage extends Page {
|
|||||||
$disabled = 'disabled';
|
$disabled = 'disabled';
|
||||||
if($this->user !== null) {
|
if($this->user !== null) {
|
||||||
$username = $this->user->get_name();
|
$username = $this->user->get_name();
|
||||||
|
$email = $this->user->get_email($this->ldap);
|
||||||
$displayname = $this->user->get_displayname($this->ldap);
|
$displayname = $this->user->get_displayname($this->ldap);
|
||||||
$notes = $this->user->get_notes();
|
$notes = $this->user->get_notes();
|
||||||
$enddate = format_date(default_loan_end(time()));
|
$enddate = format_date(default_loan_end(time()));
|
||||||
@ -45,7 +84,8 @@ class CheckoutPage extends Page {
|
|||||||
$subhead = replace(array('title' => 'Lånade artiklar'),
|
$subhead = replace(array('title' => 'Lånade artiklar'),
|
||||||
$this->fragments['subtitle']);
|
$this->fragments['subtitle']);
|
||||||
}
|
}
|
||||||
print(replace(array('user' => $this->userstr,
|
print(replace(array('user' => $username,
|
||||||
|
'email' => $email,
|
||||||
'displayname' => $displayname,
|
'displayname' => $displayname,
|
||||||
'notes' => $notes,
|
'notes' => $notes,
|
||||||
'end' => $enddate,
|
'end' => $enddate,
|
||||||
|
@ -17,7 +17,8 @@ class Ldap {
|
|||||||
public function get_user($uid) {
|
public function get_user($uid) {
|
||||||
$data = $this->search("uid=$uid", 'cn', 'uid');
|
$data = $this->search("uid=$uid", 'cn', 'uid');
|
||||||
if($data['count'] !== 1) {
|
if($data['count'] !== 1) {
|
||||||
throw new Exception("LDAP search for '$uid' did not return exactly one result");
|
$err = "LDAP search for '$uid' did not return exactly one result";
|
||||||
|
throw new Exception($err);
|
||||||
}
|
}
|
||||||
return $data[0]['cn'][0];
|
return $data[0]['cn'][0];
|
||||||
}
|
}
|
||||||
@ -25,20 +26,20 @@ class Ldap {
|
|||||||
public function get_user_email($uid) {
|
public function get_user_email($uid) {
|
||||||
$data = $this->search("uid=$uid", 'mail', 'uid');
|
$data = $this->search("uid=$uid", 'mail', 'uid');
|
||||||
if($data['count'] !== 1) {
|
if($data['count'] !== 1) {
|
||||||
throw new Exception("LDAP search for '$uid' did not return exactly one result");
|
$err = "LDAP search for '$uid' did not return exactly one result";
|
||||||
|
throw new Exception($err);
|
||||||
}
|
}
|
||||||
return $data[0]['mail'][0];
|
return $data[0]['mail'][0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function search_user($uid) {
|
public function search_email($email) {
|
||||||
$data = $this->search("uid=$uid", 'cn', 'uid');
|
$data = $this->search("mail=$email", 'mail', 'uid');
|
||||||
$out = array();
|
$out = array();
|
||||||
foreach($data as $result) {
|
if($data['count'] !== 1) {
|
||||||
if(isset($result['uid'])) {
|
$err = "LDAP search for '$email' did not return exactly one result.";
|
||||||
$out[$result['uid'][0]] = $result['cn'][0];
|
throw new Exception($err);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $out;
|
return $data[0]['uid'][0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user