View difference between Paste ID: 1gQDam3n and Nasz1vqM
SHOW: | | - or go back to the newest paste.
1
object DatabaseConnection {
2-
		private val Connection = ...
2+
	private val Connection = ...
3-
		
3+
	
4-
		private object PasswordDevice {
4+
	private object PasswordDevice {
5-
			def check(pw1: String, pw2: String) = ...
5+
		def check(pw1: String, pw2: String) = ...
6-
			def encrypt(password: String) = ...
6+
		def encrypt(password: String) = ...
7
	}
8-
		
8+
	
9-
		object LoginDevice {
9+
	object LoginDevice {
10-
			private val GetUserStatement = Connection.prepareStatement("SELECT Name, Password, Rights FROM Users WHERE UPPER(Name) = UPPER(?)")
10+
		private val GetUserStatement = Connection.prepareStatement("SELECT Name, Password, ... FROM Users WHERE UPPER(Name) = UPPER(?)")
11
12-
			def login(username: String, password: String) = {
12+
		def login(username: String, password: String) = {
13-
				GetUserStatement.setString(1, username)
13+
			GetUserStatement.setString(1, username)
14-
				val userResult = GetUserStatement.executeQuery
14+
			val userResult = GetUserStatement.executeQuery
15-
				if ( !userResult.next )
15+
			if ( !userResult.next )
16-
					throw User.NotFoundException
16+
				throw User.NotFoundException
17-
				if ( !PasswordDevice.check(password, userResult.getString("Password")) )
17+
			if ( !PasswordDevice.check(password, userResult.getString("Password")) )
18-
					throw User.WrongPasswordException
18+
				throw User.WrongPasswordException
19-
				new User(userResult.getString("Name"), ...)
19+
			new User(userResult.getString("Name"), ...)
20-
			}
20+
21
	}
22
23
24-
		object RegisterDevice {
24+
	object RegisterDevice {
25-
			private val RegisterStatement = Connection.prepareStatement("SELECT Name, Password, Rights FROM Users WHERE UPPER(Name) = UPPER(?)")
25+
		private val RegisterStatement = Connection.prepareStatement("SELECT Name, Password, ... FROM Users WHERE UPPER(Name) = UPPER(?)")
26-
			private val GetKeyStatement = Connection.prepareStatement("SELECT Key FROM Keys WHERE UPPER(Key) = UPPER(?)")
26+
		private val GetKeyStatement = Connection.prepareStatement("SELECT Key FROM Keys WHERE Key = ?")
27-
			private val InsertStatement = Connection.prepareStatement(s"INSERT INTO Users VALUES(?, ?, ...)")
27+
		private val InsertStatement = Connection.prepareStatement(s"INSERT INTO Users VALUES(?, ?, ...)")
28-
			private val DeleteKeyStatement = Connection.prepareStatement("DELETE FROM Keys WHERE Key = ?")
28+
		private val DeleteKeyStatement = Connection.prepareStatement("DELETE FROM Keys WHERE Key = ?")
29
30-
			def register(name: String, password: String, key: String) = {
30+
		def register(name: String, password: String, key: String) = {
31-
				RegisterStatement.setString(1, name)
31+
			RegisterStatement.setString(1, name)
32-
				GetKeyStatement.setString(1, key)
32+
			GetKeyStatement.setString(1, key)
33-
				val userExistsResult = RegisterStatement.executeQuery
33+
			val userExistsResult = RegisterStatement.executeQuery
34-
				val keyValidResult = GetKeyStatement.executeQuery
34+
			val keyValidResult = GetKeyStatement.executeQuery
35-
				if ( userExistsResult.next ) throw User.AlreadyExistsException
35+
			if ( userExistsResult.next ) throw User.AlreadyExistsException
36-
				if ( !keyValidResult.next ) throw User.InvalidKeyException
36+
			if ( !keyValidResult.next ) throw User.InvalidKeyException
37-
				InsertStatement.setString(1, name)
37+
			InsertStatement.setString(1, name)
38-
				InsertStatement.setString(2, PasswordDevice.encrypt(password))
38+
			InsertStatement.setString(2, PasswordDevice.encrypt(password))
39-
				InsertStatement.executeUpdate()
39+
			InsertStatement.executeUpdate()
40-
				DeleteKeyStatement.setString(1, key)
40+
			DeleteKeyStatement.setString(1, key)
41-
				DeleteKeyStatement.executeUpdate()
41+
			DeleteKeyStatement.executeUpdate()
42-
				new User(name, ...)
42+
			new User(name, ...)
43-
			}
43+
44
	}
45
46
	object RequestDevice {
47-
		object RequestDevice {
47+
		private val RequestStatement = Connection.prepareStatement("SELECT Request.* FROM Request WHERE ID = ?")
48-
			private val RequestStatement = Connection.prepareStatement("SELECT Request.* FROM Request WHERE ID = ?")
48+
49
		def request(id: String) = {
50-
			def request(id: String) = {
50+
			RequestStatement.setString(1, id)
51-
				RequestStatement.setString(1, id)
51+
			val result = RequestStatement.executeQuery
52-
				val result = RequestStatement.executeQuery
52+
			if(!result.next)
53-
				if(!result.next)
53+
				throw Request.InvalidIDException
54-
					throw Request.InvalidIDException
54+
			new DataElement(result.getString("ID"), ...)
55-
				new DataElement(result.getString("id"), ...)
55+
56-
			}
56+
	}
57
	
58-
		
58+
	...
59-
		...
59+
}