/
login.jsp
61 lines (54 loc) · 2.31 KB
/
login.jsp
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
<%@ page language="java" contentType="text/html; charset=US-ASCII"
import="com.articulate.sigma.*"
pageEncoding="US-ASCII"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
<title>login</title>
</head>
<body>
<%
/** This code is copyright Teknowledge (c) 2003, Articulate Software (c) 2003-2017,
Infosys (c) 2017-present.
This software is released under the GNU Public License
<http://www.gnu.org/copyleft/gpl.html>.
Please cite the following article in any publication with references:
Pease A., and Benzmüller C. (2013). Sigma: An Integrated Development Environment
for Logical Theories. AI Communications 26, pp79-97. See also
http://github.com/ontologyportal
*/
String userName = request.getParameter("userName");
String password = request.getParameter("password");
PasswordService ps = new PasswordService();
if (ps.userExists(userName)) {
User u = User.fromDB(ps.conn,userName);
if (u != null && ps.encrypt(password).equals(u.password)) {
session.setAttribute("user",u.username);
session.setAttribute("role",u.role);
ServletContext siblingContext = request.getSession().getServletContext().getContext("/sigma");
siblingContext.setAttribute("user",u.username);
siblingContext.setAttribute("role",u.role);
System.out.println("login.jsp: Set sibling context");
System.out.println("login.jsp: Successful login for " + u.username + " with role " + u.role);
response.sendRedirect("KBs.jsp");
}
else {
System.out.println("Bad login attempt in login.jsp - no matching password for " + u.username);
response.sendRedirect("login.html");
}
}
else {
String role = Login.validateUser(userName,password);
session.setAttribute("user",userName);
session.setAttribute("role",role);
ServletContext siblingContext = request.getSession().getServletContext().getContext("/sigma");
siblingContext.setAttribute("user",userName);
siblingContext.setAttribute("role",role);
System.out.println("login.jsp: Set sibling context");
System.out.println("login.jsp: Successful login for " + userName + " with role " + role);
response.sendRedirect("KBs.jsp");
}
%>
</body>
</html>