-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
152 lines (121 loc) · 4.04 KB
/
index.php
File metadata and controls
152 lines (121 loc) · 4.04 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
require_once 'php_action/db_connect.php';
session_start();
if(isset($_SESSION['userId'])) {
header('location:dashboard.php');
}
$errors = array();
if($_POST) {
$username = $_POST['username'];
$password = $_POST['password'];
if(empty($username) || empty($password)) {
if($username == "") {
$errors[] = "Usuario es Requerido";
}
if($password == "") {
$errors[] = "Password es Requerido";
}
} else {
$sql = "SELECT * FROM users WHERE username = '$username'";
$result = $connect->query($sql);
if($result->num_rows == 1) {
$password = md5($password);
// exists
$mainSql = "SELECT * FROM users WHERE username = '$username' AND password = '$password'";
$mainResult = $connect->query($mainSql);
if($mainResult->num_rows == 1) {
$value = $mainResult->fetch_assoc();
$user_id = $value['user_id'];
$profile = $value['profile_id'];
// set session
$_SESSION['userId'] = $user_id;
$_SESSION['profile'] = $profile;
$primeraPag = "SELECT b.page_url FROM functions a
inner join page b on a.page_id = b.page_id
where a.profile_id = $profile
and b.page_url != '#'
order by b.parent_node, b.page_order
limit 1";
$primeraPagResult = $connect->query($primeraPag);
$primeraPagVal = $primeraPagResult->fetch_assoc();
header('location:'.$primeraPagVal['page_url']);
} else {
$errors[] = "Combinacion user/password incorrecta.";
} // /else
} else {
$errors[] = "Combinacion user/password incorrecta.";
} // /else
} // /else not empty username // password
} // /if $_POST
?>
<!DOCTYPE html>
<html>
<head>
<title>Sistema de Administracion de Stock</title>
<!-- bootstrap -->
<link rel="stylesheet" href="assests/bootstrap/css/bootstrap.min.css">
<!-- bootstrap theme-->
<link rel="stylesheet" href="assests/bootstrap/css/bootstrap-theme.min.css">
<!-- font awesome -->
<link rel="stylesheet" href="assests/font-awesome/css/font-awesome.min.css">
<!-- custom css -->
<link rel="stylesheet" href="custom/css/custom.css">
<!-- jquery -->
<script src="assests/jquery/jquery.min.js"></script>
<!-- jquery ui -->
<link rel="stylesheet" href="assests/jquery-ui/jquery-ui.min.css">
<script src="assests/jquery-ui/jquery-ui.min.js"></script>
<!-- bootstrap js -->
<script src="assests/bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="row vertical">
<div class="col-md-5 col-md-offset-4">
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">Iniciar sesion</h3>
</div>
<div class="panel-body">
<div class="messages">
<?php if($errors) {
foreach ($errors as $key => $value) {
echo '<div class="alert alert-warning" role="alert">
<i class="glyphicon glyphicon-exclamation-sign"></i>
'.$value.'</div>';
}
} ?>
</div>
<form class="form-horizontal" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" id="loginForm">
<fieldset>
<div class="form-group">
<label for="username" class="col-sm-2 control-label">Usuario</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="username" name="username" placeholder="Username" autocomplete="off" />
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-2 control-label">Password</label>
<div class="col-sm-10">
<input type="password" class="form-control" id="password" name="password" placeholder="Password" autocomplete="off" />
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default"> <i class="glyphicon glyphicon-log-in"></i> Ingresar</button>
</div>
</div>
</fieldset>
</form>
</div>
<!-- panel-body -->
</div>
<!-- /panel -->
</div>
<!-- /col-md-4 -->
</div>
<!-- /row -->
</div>
<!-- container -->
</body>
</html>