-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
92 lines (87 loc) · 3.22 KB
/
index.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
<head>
<?php include_once (__DIR__.'/head.php'); ?>
</head>
<body>
<?php
include_once (__DIR__.'/Util/init.php');
if($loggedIn){
$user = Session::get(Session::USER);
//redirect
if($user[User::ROLE] == User::ADMIN){
Util::redirect("/positive/admin");
}else if($user[User::ROLE] == User::PERSONEL){
Util::redirect("/positive/personel");
}else if($user[User::ROLE] == User::BRANCH){
Util::redirect("/positive/branch");
}else if($user[User::ROLE] == User::FINANCE){
Util::redirect("/positive/finans");
}
}
if(!empty($_POST)){
$loginService = new LoginService();
$username = Util::cleanInput($_POST['username']);
$password = Util::cleanInput($_POST['password']);
$remember = isset($_POST['remember']) ? true : false;
$logger->write(ALogger::INFO, __FILE__, "Login request come [".$username."]");
$user = $loginService->login($username, $password);
//put to session
if($user[User::ROLE] > 0){
$logger->write(ALogger::INFO, __FILE__, "Logged in [".$username."]");
Session::put(Session::USER, $user);
if($remember){
$hash = Hash::unique();
Cookie::put(Cookie::HASH, $hash, Cookie::REMEMBER_EXPIRE);
$loginService->remember($user[User::ID], $hash);
}
}else{
$logger->write(ALogger::INFO, __FILE__, "Could not Logged in [".$username."]");
}
//redirect
if($user[User::ROLE] == User::ADMIN){
Util::redirect("/positive/admin");
}else if($user[User::ROLE] == User::PERSONEL){
Cookie::delete('companies');
Util::redirect("/positive/personel");
}else if($user[User::ROLE] == User::BRANCH){
Util::redirect("/positive/branch");
}else if($user[User::ROLE] == User::FINANCE){
Util::redirect("/positive/finans");
}
}
?>
<div class="container login_form">
<form class="form-signin" id="positive_login" action="" method="post" autocomplete="off">
<h2 class="form-signin-heading">
<img src="images/positive.png" class="login_image">  Giriş Yapınız
</h2>
<label for="username" class="login-error" id="login-error"></label>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">Kod</span>
<input type="text" class="form-control" aria-describedby="basic-addon1" id="username" name="username">
</div>
<br>
<div class="input-group">
<span class="input-group-addon" id="basic-addon1">Şifre</span>
<input type="password" class="form-control" aria-describedby="basic-addon1" id="password" name="password">
</div>
<div class="checkbox">
<label>
<input type="checkbox" id="remember" name="remember" value="remember-me"> Beni Hatırla
</label>
</div>
<button class="btn btn-lg btn-primary btn-block" type="button" id="login_button">Giriş</button>
</form>
</div>
<script src="/positive/js/login.js"></script>
<?php
if(!empty($_POST)){
echo "<script type='text/javascript'>";
if($user[User::ROLE] == User::USER_NOT_FOUND){
echo "$('#login-error').html('Böyle bir kullanıcı adı kayıtlı değil.');";
}else if($user[User::ROLE] == User::WRONG_PASS){
echo "$('#login-error').html('Kullanıcı adı-şifre hatalı.');";
}
echo "</script>";
}
?>
</body>