-
Notifications
You must be signed in to change notification settings - Fork 38
/
AccountController.php
executable file
·102 lines (84 loc) · 3.29 KB
/
AccountController.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
<?php
class AccountController extends BaseController
{
public function createAccountView()
{
return View::make('account/create');
}
public function createAccountSubmit()
{
$rules = array(
"username" => "required|min:6",
"password" => "required|min:6",
"confirm_password" => "required|same:password",
"email" => "required",
);
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails()) {
$messages = $validator->messages();
return Redirect::to("create")
->withInput(Input::except('password', 'password_confirm'))
->withErrors($validator);
}
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$username = $_POST['username'];
$password = $_POST['password'];
$confirm_password = $_POST['confirm_password'];
$email = $_POST['email'];
$organization = $_POST['organization'];
$address = $_POST['address'];
$country = $_POST['country'];
$telephone = $_POST['telephone'];
$mobile = $_POST['mobile'];
$im = $_POST['im'];
$url = $_POST['url'];
if (WSIS::usernameExists($username)) {
return Redirect::to("create")
->withInput(Input::except('password', 'password_confirm'))
->with("username_exists", true);
} else {
WSIS::addUser($username, $password, $first_name, $last_name, $email, $organization,
$address, $country, $telephone, $mobile, $im, $url);
CommonUtilities::print_success_message('New user created!');
return View::make('home');
}
}
public function loginView()
{
return View::make('account/login');
}
public function loginSubmit()
{
if (CommonUtilities::form_submitted()) {
$username = $_POST['username'];
$password = $_POST['password'];
try {
if (WSIS::authenticate($username, $password)) {
if (in_array(Config::get('pga_config.wsis')['admin-role-name'], (array)WSIS::getUserRoles($username))) {
Session::put("admin", true);
}
CommonUtilities::store_id_in_session($username);
CommonUtilities::print_success_message('Login successful! You will be redirected to your home page shortly.');
Session::put("gateway_id", Config::get('pga_config.wsis')['gateway-id']);
//TODO::If this option is not safe, have to find a better method to send credentials to identity server on every connection.
Session::put("password", $_POST["password"]);
return Redirect::to("home");
} else {
return Redirect::to("login")->with("invalid-credentials", true);
}
} catch (Exception $ex) {
return Redirect::to("login")->with("invalid-credentials", true);
}
}
}
public function forgotPassword()
{
return View::make("account/forgot-password");
}
public function logout()
{
Session::flush();
return Redirect::to('home');
}
}