-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/UI' into UI
- Loading branch information
Showing
6 changed files
with
182 additions
and
27 deletions.
There are no files selected for viewing
27 changes: 0 additions & 27 deletions
27
app/src/androidTest/java/com/example/multiplechoice/ExampleInstrumentedTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.example.multiplechoice; | ||
|
||
import java.io.IOException; | ||
import java.net.HttpURLConnection; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
public class User implements Users { | ||
|
||
|
||
|
||
@Override | ||
public int login(String username,String password) { | ||
int response = 0; | ||
|
||
try { | ||
URL url= new URL("http://localhost/icd_tei_ser/script/user/log_in.php?username="+username+"&password="+password); | ||
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||
connection.connect(); | ||
response = connection.getResponseCode(); | ||
return response; | ||
|
||
}catch (IOException ex) { | ||
Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex); | ||
} | ||
|
||
return response; | ||
} | ||
|
||
@Override | ||
public int register(String username, String email, String password) { | ||
int response = 0; | ||
try { | ||
URL url= new URL("http://localhost/icd_tei_ser/script/user/register.php?username="+username+"&email="+email+"&password="+password); | ||
System.out.println(url); | ||
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); | ||
connection.connect(); | ||
response = connection.getResponseCode(); | ||
} catch (MalformedURLException ex) { | ||
Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex); | ||
} catch (IOException ex) { | ||
Logger.getLogger(User.class.getName()).log(Level.SEVERE, null, ex); | ||
} | ||
return response; | ||
} | ||
|
||
@Override | ||
public boolean isTheSame(String password, String confirmation) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public int changePassword(String username, String email, String password) { | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.example.multiplechoice; | ||
|
||
import java.io.IOException; | ||
import java.net.MalformedURLException; | ||
|
||
public interface Users { | ||
/** | ||
* <p> | ||
* This method will let the user login by passing the strings from <b>editUsernameText</b> and <b>editPasswordText</b> | ||
* to the server. This is achieved by using <b><a href='https://docs.oracle.com/javase/8/docs/api/java/net/HttpURLConnection.html'>HttpURLConnection()</a></b> | ||
* and a <b>log_in.php</b> script which is stored on a remote server. | ||
* </p> | ||
* @param username user's username | ||
* @param password user's password | ||
* @return returns the integer from getResponseCode() | ||
*/ | ||
int login(String username, String password); | ||
/** | ||
* <p> | ||
* This method will let the user register by passing the strings from <b>editUsernameText</b> and <b>editPasswordText</b> | ||
* to the server. This is achieved by using <b><a href='https://docs.oracle.com/javase/8/docs/api/java/net/HttpURLConnection.html'>HttpURLConnection()</a></b> | ||
* and a <b>register.php</b> script which is stored on a remote server. The register.php script makes sure that the username and email are unique. | ||
* </p> | ||
* @param username user's username | ||
* @param email user's email | ||
* @param password user's password | ||
* | ||
* @return returns the integer from getResponseCode() | ||
*/ | ||
int register(String username, String email, String password); | ||
boolean isTheSame(String password, String confirmation); | ||
int changePassword(String username, String email, String password); | ||
|
||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
<resources> | ||
<string name="app_name">Multiple Choice</string> | ||
|
||
<string name="password">Password</string> | ||
<string name="logo">Logo</string> | ||
<string name="email">Email</string> | ||
|
||
<string name="username">Username</string> | ||
|
||
</resources> |
42 changes: 42 additions & 0 deletions
42
app/src/test/java/com/example/multiplechoice/LoginTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.example.multiplechoice; | ||
|
||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.net.MalformedURLException; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class LoginTest { | ||
|
||
@Test | ||
public void isValid(){ | ||
User user = new User(); | ||
String username = "volpym"; | ||
String password = "ac0b3pass"; | ||
int expected = 200; | ||
int output = user.login(username,password); | ||
assertEquals(expected,output); | ||
} | ||
@Test | ||
public void isWrongPassword(){ | ||
User user = new User(); | ||
String username = "volpym"; | ||
String password = "ac0b3pas2"; | ||
int expected = 401; | ||
int output = user.login(username,password); | ||
|
||
} | ||
@Test | ||
public void userDoesNotExist(){ | ||
User user = new User(); | ||
String username = "volpym234"; | ||
String password = "ac0b3pass"; | ||
int expected = 404; | ||
int output = user.login(username,password); | ||
|
||
} | ||
|
||
|
||
|
||
} |
40 changes: 40 additions & 0 deletions
40
app/src/test/java/com/example/multiplechoice/RegisterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.example.multiplechoice; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
public class RegisterTest { | ||
|
||
@Test | ||
public void canRegister() { | ||
User user = new User(); | ||
String username = "geralt"; | ||
String email = "[email protected]"; | ||
String password = "roach"; | ||
int expected = 200; | ||
int output = user.register(username, email,password); | ||
assertEquals(expected, output); | ||
|
||
} | ||
@Test | ||
public void userExistsButNotEmail() { | ||
User user = new User(); | ||
String username = "geralt"; | ||
String email = "[email protected]"; | ||
String password = "roach"; | ||
int expected = 403; | ||
int output = user.register(username, email,password); | ||
assertEquals(expected, output); | ||
} | ||
@Test | ||
public void emailExistsButNotUser() { | ||
User user = new User(); | ||
String username = "geraltOfRivia2009"; | ||
String email = "[email protected]"; | ||
String password = "roach"; | ||
int expected = 403; | ||
int output = user.register(username, email,password); | ||
assertEquals(expected, output); | ||
} | ||
} |