Skip to content
This repository has been archived by the owner on Mar 25, 2021. It is now read-only.

Commit

Permalink
closes #19 Make sure users are in attendance when they log on.
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Druid committed Dec 26, 2010
1 parent b14a1a0 commit ef8432b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion classes/Network.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function is_local($mac = null){
if($mac == null){
$mac = self::get_mac();
}
return preg_match('/^([0-9A-F]{1,2}:){5}[0-9A-F]{1,2}$/i', $mac);
return preg_match('/^([0-9A-F]{1,2}:){5}[0-9A-F]{1,2}$/i', $mac) || $mac == '127.0.0.1';
}
}
?>
3 changes: 3 additions & 0 deletions classes/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public static function clear_old_sessions() {
'time:<' => date('Y-m-d H:i:s', time()-self::TIMEOUT),
));
foreach($sessions as $session){
if(Network::is_local($session->mac)) {
$session->User->set_attending();
}
$session->delete();
}
}
Expand Down
15 changes: 15 additions & 0 deletions classes/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ public function has_password($password) {
return $crypt == $this->password;
}

public function set_attending($day = null) {
if($day == null) {
$day = date('Y-m-d');
}
try{
$attendance = new Attendance();
$attendance->user_id = $this->id;
$attendance->day = $day;
$attendance->commit();
} catch(Exception $e){
return $e->getMessage();
}
return null;
}

public static function from_username($username) {
return parent::from_field('username', $username);
}
Expand Down
12 changes: 10 additions & 2 deletions controllers/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,22 @@ public function make($params) {
$session->mac = Network::get_mac();
$session->internet = $user->has_access('internet') && Network::is_local($session->mac);
$session->commit();
if(Network::is_local()) {
$user->set_attending();
}
Message::add_notice("Välkommen {$user->first_name}");
URL::redirect($_SERVER['HTTP_REFERER']);
}

public function delete($params) {
$this->_access_type('script');
$session = Session::from_id(session_id());
$session->delete();
global $current_user, $session;
if($session != null) {
if(Network::is_local($session->mac)) {
$current_user->set_attending();
}
$session->delete();
}
session_destroy();
URL::redirect('');
}
Expand Down

0 comments on commit ef8432b

Please sign in to comment.