-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuserClass.php
103 lines (90 loc) · 2.64 KB
/
userClass.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* user Class
* used for user login primarily
*/
namespace Cat;//shouldnt be in this namespace, maybe User
require_once 'classDatabase.php';
use PDO;
use PDOException;
class userClass
{
protected $username;
protected $password;
/*public function __construct($username, $password)
{
$this->username = $username;
$this->password = $password;
}*/
/**
* User Login
* @param $usernameEmail
* @param $password
* @return bool
*/
public function userLogin($username, $password)
{
$db = Database::getFactory()->getConnection();
try {
/*$stmt = $db->prepare("SELECT uid .'
. 'FROM userLogin .'
.'WHERE userName=:username. '
. 'AND userPass=:password");*/
$stmt = $db->prepare("SELECT uid FROM userLogin WHERE userName=:username AND userPass=:password");
//@TODO:hash salt password
$stmt->bindParam(':username', $username,PDO::PARAM_STR) ;
$stmt->bindParam(':password', $password,PDO::PARAM_STR) ;
$stmt->execute();
$count=$stmt->rowCount();
$data=$stmt->fetch(PDO::FETCH_OBJ);
$db = null;
if ($count) {
$_SESSION['uid']=$data->uid; //storing user session value
return true;
} else {
return false;
}
} catch(\PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
error_log('db connection issue', 0);
}
}
/**
* User Details
* @param $uid
* @return mixed
*/
public function userDetails($uid)
{
/**
* instead of getFactory set up something
* lik getRow, updateRow
*/
try{
$db = Database::getFactory()->getConnection();
$stmt = $db->prepare("SELECT email FROM userLogin WHERE uid=:uid");
$stmt->bindParam("uid", $uid,PDO::PARAM_INT);
$stmt->execute();
$data = $stmt->fetch(PDO::FETCH_OBJ); //user data
return $data;
}
catch(PDOException $e) {
echo '{"error":{"text":'. $e->getMessage() .'}}';
}
}
/**
* Create Password
* @param int $length
* @return string
*/
private function createPassword($length = 50)
{
//create random password with 8 alpha characters
$characters = '0123456789abcdefghijklmnopqrstuvwxyz';
$string = '';
for ($p = 0; $p < $length; $p++) {
$string .= $characters[mt_rand(0, strlen($characters))];
}
return $string;
}
}