From 6919dc98ea4d546aea56e815c22fecc3a6c164c8 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 26 Apr 2015 20:07:58 +1200 Subject: Change user name to email --- src/org/traccar/database/DataManager.java | 14 +++++++------- src/org/traccar/http/MainServlet.java | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'src/org/traccar') diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 5e12dc865..4b8f4d5e8 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -239,7 +239,7 @@ public class DataManager { statement.execute( "CREATE TABLE user (" + "id INT PRIMARY KEY AUTO_INCREMENT," + - "name VARCHAR(1024) NOT NULL UNIQUE," + + "email VARCHAR(1024) NOT NULL UNIQUE," + "password VARCHAR(1024) NOT NULL," + "salt VARCHAR(1024) NOT NULL," + "readonly BOOLEAN DEFAULT false NOT NULL," + @@ -322,15 +322,15 @@ public class DataManager { } } - public long login(String name, String password) throws SQLException { + public long login(String email, String password) throws SQLException { Connection connection = dataSource.getConnection(); try { PreparedStatement statement = connection.prepareStatement( - "SELECT id FROM user WHERE name = ? AND " + + "SELECT id FROM user WHERE email = ? AND " + "password = CAST(HASH('SHA256', STRINGTOUTF8(?), 1000) AS VARCHAR);"); try { - statement.setString(1, name); + statement.setString(1, email); statement.setString(2, password); ResultSet result = statement.executeQuery(); @@ -344,15 +344,15 @@ public class DataManager { } } - public void addUser(String name, String password, boolean admin) throws SQLException { + public void addUser(String email, String password, boolean admin) throws SQLException { Connection connection = dataSource.getConnection(); try { PreparedStatement statement = connection.prepareStatement( - "INSERT INTO user (name, password, salt, admin) " + + "INSERT INTO user (email, password, salt, admin) " + "VALUES (?, CAST(HASH('SHA256', STRINGTOUTF8(?), 1000) AS VARCHAR), '', ?);"); try { - statement.setString(1, name); + statement.setString(1, email); statement.setString(2, password); statement.setBoolean(3, admin); diff --git a/src/org/traccar/http/MainServlet.java b/src/org/traccar/http/MainServlet.java index 655b47312..65a1bf624 100644 --- a/src/org/traccar/http/MainServlet.java +++ b/src/org/traccar/http/MainServlet.java @@ -240,7 +240,7 @@ public class MainServlet extends HttpServlet { private void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try { req.getSession().setAttribute(USER_ID, - Context.getDataManager().login(req.getParameter("name"), req.getParameter("password"))); + Context.getDataManager().login(req.getParameter("email"), req.getParameter("password"))); resp.getWriter().println("{ success: true }"); } catch (SQLException e) { throw new ServletException(e); -- cgit v1.2.3