Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ dependencies {
implementation 'com.android.support:cardview-v7:27.0.2'
implementation 'com.android.support:support-v4:27.0.2'
compile 'com.android.support.constraint:constraint-layout:1.1.0-beta4'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'
implementation 'com.android.support:design:27.0.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.djunicode.queuingapp">

<uses-permission android:name="android.permission.INTERNET"/>

<supports-screens
android:anyDensity="true"
android:largeScreens="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,18 @@
import android.widget.Toast;
import com.djunicode.queuingapp.R;
import com.djunicode.queuingapp.SessionManagement.SessionManager;
import com.djunicode.queuingapp.customClasses.HashingPassword;
import com.djunicode.queuingapp.fragment.FindTeacherFragment;
import com.djunicode.queuingapp.fragment.LogInStudentFragment;
import com.djunicode.queuingapp.fragment.LogInTeacherFragment;
import com.djunicode.queuingapp.fragment.SignUpTeacherFragment;
import com.djunicode.queuingapp.model.Student;
import com.djunicode.queuingapp.model.StudentForId;
import com.djunicode.queuingapp.rest.ApiClient;
import com.djunicode.queuingapp.rest.ApiInterface;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class LogInActivity extends AppCompatActivity {

Expand All @@ -36,12 +44,16 @@ public class LogInActivity extends AppCompatActivity {
private Spinner departmentSpinner, yearSpinner, batchSpinner;
private TextView logInStudentTextView, logInTeacherTextView, signUpTeacherTextView;
private CardView signUpStudentButton;
private String username, department, year, batch, SAPId, password; //Student's data to be send to server
private TextInputLayout studentSignUpinputLayoutUsername, studentSignUpinputLayoutSAPId,
studentSignUpinputLayoutPassword, studentSignUpinputLayoutDepartment,
studentSignUpinputLayoutYear, batchSpinnerLayout;
private SharedPreferences sp_student, sp_teacher;
// Session Manager Class
SessionManager session;
ApiInterface apiInterface;
private String salt, intermediate_password, hashed_password;
int idFromServer;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -64,18 +76,14 @@ protected void onCreate(Bundle savedInstanceState) {
logInTeacherTextView = (TextView) findViewById(R.id.logInTeacherTextView);
signUpTeacherTextView = (TextView) findViewById(R.id.signUpTeacherTextView);
signUpStudentButton = (CardView) findViewById(R.id.signUpStudentButton);
apiInterface = ApiClient.getClient().create(ApiInterface.class);

//studentSignUpinputLayoutUsername.setError(getString(R.string.err_msg_username));

String username = usernameEditText.getText().toString();
String sapID = sapIDEditText.getText().toString();
String password = passwordEditText.getText().toString();
sp_student = getSharedPreferences("Student",MODE_PRIVATE);
sp_teacher = getSharedPreferences("Teacher",MODE_PRIVATE);

// To remove Locally stored variables remove the below comment

/*Editor editor_student = sp_student.edit();
Editor editor_student = sp_student.edit();
Editor editor_teacher = sp_teacher.edit();

editor_student.remove("student_username");
Expand All @@ -84,7 +92,7 @@ protected void onCreate(Bundle savedInstanceState) {

editor_teacher.remove("teacher_username");
editor_teacher.remove("teacher_password");
editor_teacher.commit();*/
editor_teacher.commit();

//if SharedPreferences contains username and password then redirect to Home activity
if(sp_student.contains("student_username") && sp_student.contains("student_password")){
Expand All @@ -97,7 +105,7 @@ protected void onCreate(Bundle savedInstanceState) {

if(sp_teacher.contains("teacher_username") && sp_teacher.contains("teacher_password")){
Toast.makeText(getApplicationContext(), "I got it!", Toast.LENGTH_SHORT).show();
Intent in = new Intent(this, TeacherScreenActivity.class);
Intent in = new Intent(this, StudentScreenActivity.class);
// StudentScreenActivity just for demo till the time teacher fragments are not ready
startActivity(in);

Expand Down Expand Up @@ -198,6 +206,14 @@ public void onClick(View v) {
@Override
public void onClick(View v) {
if (validSignUp()) {
username = usernameEditText.getText().toString();
department = departmentSpinner.getSelectedItem().toString();
year = yearSpinner.getSelectedItem().toString();
batch = batchSpinner.getSelectedItem().toString();
SAPId = sapIDEditText.getText().toString();
password = passwordEditText.getText().toString();
hash_password(password); //Hash the password before sending it to the server
getIdForStudentFromUser();
session.createLoginSession(usernameEditText.getText().toString(),
passwordEditText.getText().toString());
Intent intent = new Intent(LogInActivity.this, StudentScreenActivity.class);
Expand Down Expand Up @@ -225,6 +241,10 @@ private Boolean validSignUp () {
return false;
}

if (!validateBatch()) {
return false;
}

if (!validateSAPId()) {
return false;
}
Expand Down Expand Up @@ -308,11 +328,63 @@ private boolean validateYear() {
}
}

private boolean validateBatch() {
if(batchSpinner.getSelectedItemPosition() == 0) {
batchSpinnerLayout.setError(getString(R.string.err_msg_batch));
return false;
}
else {
batchSpinnerLayout.setError("");
return true;
}
}

private void requestFocus(View view) {
if (view.requestFocus()) {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}
}

private void sendDataToServer(int id) {
Log.i("id", Integer.toString(id));
Call<Student> call = apiInterface.createStudentAccount(id, username, SAPId, department, year, batch);
call.enqueue(new Callback<Student>() {
@Override
public void onResponse(Call<Student> call, Response<Student> response) {
// Log.i("student", response.body().toString());
}

@Override
public void onFailure(Call<Student> call, Throwable t) {

}
});
}

private void hash_password (String password) {

HashingPassword hashingPassword = new HashingPassword();
salt = hashingPassword.generate_salt();
intermediate_password = password + salt;
hashed_password = hashingPassword.hash_the_password(intermediate_password);
}

private void getIdForStudentFromUser () {
Call<StudentForId> call = apiInterface.getId(username, hashed_password);
call.enqueue(new Callback<StudentForId>() {
@Override
public void onResponse(Call<StudentForId> call, Response<StudentForId> response) {
Log.i("idFromServer", Integer.toString(response.body().getId()));
sendDataToServer(response.body().getId());

}

@Override
public void onFailure(Call<StudentForId> call, Throwable t) {

}
});

}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.djunicode.queuingapp.customClasses;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
* Created by DELL_PC on 23-01-2018.
*/

public class HashingPassword {

private static final String ALPHA_NUMERIC_STRING = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
public String generate_salt() {
int count = 16;
StringBuilder builder = new StringBuilder();
while (count-- != 0) {
int character = (int)(Math.random()*ALPHA_NUMERIC_STRING.length());
builder.append(ALPHA_NUMERIC_STRING.charAt(character));
}
return builder.toString();
}

public String hash_the_password(String input) {
StringBuilder hash = new StringBuilder();

try {
MessageDigest sha = MessageDigest.getInstance("SHA-1");
byte[] hashedBytes = sha.digest(input.getBytes());
char[] digits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'a', 'b', 'c', 'd', 'e', 'f' };
for (int idx = 0; idx < hashedBytes.length; ++idx) {
byte b = hashedBytes[idx];
hash.append(digits[(b & 0xf0) >> 4]);
hash.append(digits[b & 0x0f]);
}
} catch (NoSuchAlgorithmException e) {
// handle error here.
}

return hash.toString();
}

public boolean isExpectedPassword(String password, String salt, String expectedHash) {
String fina = password + salt;
String s = hash_the_password(fina);
if(s.equals(expectedHash))
return true;
else
return false;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.djunicode.queuingapp.customClasses;

import android.util.Log;
import com.djunicode.queuingapp.model.LocationTeacher;
import com.djunicode.queuingapp.rest.ApiClient;
import com.djunicode.queuingapp.rest.ApiInterface;
import java.util.TimerTask;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
* Created by DELL_PC on 23-01-2018.
*/

public class TeacherTimerTask extends TimerTask{

ApiInterface apiInterface = ApiClient.getClient().create(ApiInterface.class);
int i = 19;

@Override
public void run() {

Call<LocationTeacher> call = apiInterface.deleteTeacherLocation(i);
call.enqueue(new Callback<LocationTeacher>() {
@Override
public void onResponse(Call<LocationTeacher> call, Response<LocationTeacher> response) {
Log.i("Info", "Deleted");
}

@Override
public void onFailure(Call<LocationTeacher> call, Throwable t) {
Log.i("Info", "Deletion failed");
}
});

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.CardView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
Expand All @@ -19,6 +20,12 @@
import android.widget.Toast;
import com.djunicode.queuingapp.R;
import com.djunicode.queuingapp.activity.SightedTeacherActivity;
import com.djunicode.queuingapp.model.LocationTeacher;
import com.djunicode.queuingapp.rest.ApiClient;
import com.djunicode.queuingapp.rest.ApiInterface;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
* A simple {@link Fragment} subclass.
Expand All @@ -27,6 +34,8 @@ public class FindTeacherFragment extends Fragment {

private Spinner subjectSpinner, teacherSpinner;
private CardView findTeacherButton, sightedTeacherButton;
ApiInterface apiInterface;


public FindTeacherFragment() {
// Required empty public constructor
Expand All @@ -46,6 +55,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
teacherSpinner = (Spinner) view.findViewById(R.id.teacherSpinner);
findTeacherButton = (CardView) view.findViewById(R.id.findTeacherButton);
sightedTeacherButton = (CardView) view.findViewById(R.id.sightedTeacherButton);
apiInterface = ApiClient.getClient().create(ApiInterface.class);

ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(),
android.R.layout.simple_spinner_dropdown_item, array);
Expand Down Expand Up @@ -74,16 +84,52 @@ public void onNothingSelected(AdapterView<?> parent) {
findTeacherButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(teacherSpinner.getSelectedItemPosition() != 0){
/*if(teacherSpinner.getSelectedItemPosition() != 0){
String location = "Prof. " + teacherSpinner.getSelectedItem().toString() +
" is in the staff lounge.";
AlertDialog.Builder builder = new Builder(getActivity());
builder.setMessage(location)
.setPositiveButton("OK", null)
.show();
}
else
Toast.makeText(getContext(), "Please Select a teacher!", Toast.LENGTH_SHORT).show();*/
if(teacherSpinner.getSelectedItemPosition() != 0) {
int i = 22;
Call<LocationTeacher> call = apiInterface.getTeacherLocation(i);
call.enqueue(new Callback<LocationTeacher>() {
@Override
public void onResponse(Call<LocationTeacher> call, Response<LocationTeacher> response) {
/*Log.i("Id", response.body().getId().toString());
Log.i("Floor", response.body().getFloor().toString());
Log.i("Department", response.body().getDepartment());
Log.i("Room", response.body().getRoom());
Log.i("Updated At", response.body().getUpdated_at());*/
String location = "Prof. " + teacherSpinner.getSelectedItem().toString() +
"is at " + response.body().getFloor().toString() + "floor's " + response.body().getDepartment()
+ "department and " + response.body().getRoom() + "room.";
AlertDialog.Builder builder = new Builder(getActivity());
builder.setMessage(location)
.setPositiveButton("OK", null)
.show();
}

@Override
public void onFailure(Call<LocationTeacher> call, Throwable t) {
if(t != null) {
Log.i("info: ", t.getMessage());
}
else {
Log.i("info: ", "failed");
}
}
});

}

else
Toast.makeText(getContext(), "Please Select a teacher!", Toast.LENGTH_SHORT).show();

}
});

Expand All @@ -97,4 +143,4 @@ public void onClick(View v) {

return view;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ private boolean validatePassword() {
}

private boolean validMatch() {
if(sapIdLogInEditText.getText().toString().equals("dhruv") &&
if(sapIdLogInEditText.getText().toString().equals("60004160006") &&
passwordLogInEditText.getText().toString().equals("demopass")) {

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private boolean validatePassword() {
}

private boolean validMatch() {
if(sapIdLogInTeacherEditText.getText().toString().equals("dhruv") &&
if(sapIdLogInTeacherEditText.getText().toString().equals("60004160006") &&
passwordLogInTeacherEditText.getText().toString().equals("demopass")) {

return true;
Expand Down
Loading