PluginProbe
ShiftController Employee Shift Scheduling / trunk
ShiftController Employee Shift Scheduling vtrunk
4.9.97 4.9.96 4.9.95 4.9.74 4.9.75 4.9.76 4.9.77 4.9.78 4.9.84 4.9.85 4.9.87 4.9.91 4.9.92 trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.2.4 All 38 releases
shiftcontroller / hc3 / _wordpress / auth.php

auth.php in ShiftController Employee Shift Scheduling trunk, at hc3/_wordpress/auth.php

69 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php if (! defined('ABSPATH')) exit; // Exit if accessed directly
2 class HC3_Auth implements HC3_IAuth
3 {
4 public $self, $hooks, $usersQuery;
5
6 public function __construct(
7 HC3_Hooks $hooks,
8 HC3_Users_Query $usersQuery
9 )
10 {
11 $this->hooks = $hooks;
12 $this->self = $hooks->wrap( $this );
13 $this->usersQuery = $hooks->wrap( $usersQuery );
14 }
15
16 public function getCurrentUserId()
17 {
18 $return = get_current_user_id();
19 return $return;
20 }
21
22 public function getCurrentUser()
23 {
24 $id = $this->self->getCurrentUserId();
25 $return = $this->usersQuery->findById( $id );
26 if( ! $return ){
27 $return = $this->usersQuery->findById(0);
28 }
29 return $return;
30 }
31
32 public function getUserByToken( $token )
33 {
34 $return = NULL;
35
36 $args = array();
37 $prefix = $this->hooks->getPrefix();
38 $metaName = $prefix . 'token';
39 $args[] = array( $metaName, '=', $token );
40 $args[] = array( 'limit', 1 );
41
42 $users = $this->usersQuery->read( $args );
43 if( $users ){
44 $return = array_shift( $users );
45 }
46
47 return $return;
48 }
49
50 public function getTokenByUser( HC3_Users_Model $user )
51 {
52 $return = NULL;
53
54 $id = $user->getId();
55 if( $id ){
56 $prefix = $this->hooks->getPrefix();
57 $metaName = $prefix . 'token';
58 $return = get_user_meta( $id, $metaName, TRUE );
59
60 if( ! strlen($return) ){
61 $return = HC3_Functions::generateRand(12);
62 update_user_meta( $id, $metaName, $return );
63 }
64 }
65
66 return $return;
67 }
68
69 }