Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/UI' into UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Volpym committed Oct 13, 2019
2 parents 48910f1 + d651d73 commit 70d0d0d
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 27 deletions.

This file was deleted.

58 changes: 58 additions & 0 deletions app/src/main/java/com/example/multiplechoice/User.java
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;
}
}
36 changes: 36 additions & 0 deletions app/src/main/java/com/example/multiplechoice/Users.java
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);



}
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
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 app/src/test/java/com/example/multiplechoice/LoginTest.java
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 app/src/test/java/com/example/multiplechoice/RegisterTest.java
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);
}
}

0 comments on commit 70d0d0d

Please sign in to comment.