Guest User

Untitled

a guest
Oct 18th, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.45 KB | None | 0 0
  1. I/qtaguid﹕ Failed write_ctrl(u 43) res=-1 errno=22
  2. I/qtaguid﹕ Untagging socket 43 failed errno=-22
  3. W/NetworkManagementSocketTagger﹕ untagSocket(43) failed with errno -22
  4.  
  5. public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
  6.  
  7. // Define Views
  8. private EditText editTextEmail, editTextPassword;
  9. private Button buttonLogin;
  10. private ProgressBar progress;
  11. private UserLocalStore userLocalStore;
  12.  
  13. private boolean loggedIn = false;
  14. private final String TAG = "";
  15.  
  16. @Override
  17. protected void onCreate(Bundle savedInstanceState) {
  18. super.onCreate(savedInstanceState);
  19.  
  20. getSupportActionBar().hide(); // Hides the Action Bar for Login Activity
  21.  
  22. setContentView(R.layout.activity_login); // Sets the Content View
  23.  
  24. // Initializing Views
  25.  
  26. // EditText fields
  27. editTextEmail = (EditText) findViewById(R.id.editTextEmail);
  28. editTextPassword = (EditText) findViewById(R.id.editTextPassword);
  29.  
  30. // Buttons
  31. buttonLogin = (Button) findViewById(R.id.buttonLogin);
  32.  
  33. // Other
  34. progress = (ProgressBar) findViewById(R.id.progressBar);
  35.  
  36. // This method will set watcher for the EditTextFields
  37. // The method will watch the value set to the EditTextFields.
  38. // If there is nothing inputted in the EditTextField, "Login" button is disabled.
  39. // Correspondingly, if there are text in the field, "Login" button is enabled.
  40. watcher(editTextEmail, editTextPassword, buttonLogin);
  41.  
  42.  
  43. // On-Click listeners
  44. buttonLogin.setOnClickListener(this);
  45.  
  46. }
  47.  
  48. // Watcher method to check the value of EditText field
  49. public void watcher(final EditText editText, final EditText editPassword, final Button button)
  50. {
  51. editText.addTextChangedListener(new TextWatcher() {
  52. public void afterTextChanged(Editable s) {
  53.  
  54. if (editText.length() == 0 && editPassword.length() == 0) // If length of the text field is equal to 0
  55. button.setEnabled(false); // Disable the "Send" button
  56. else
  57. button.setEnabled(true); // Otherwise enable
  58.  
  59. }
  60.  
  61. public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  62. }
  63.  
  64. public void onTextChanged(CharSequence s, int start, int before, int count) {
  65. }
  66. });
  67.  
  68. if(editText.length() == 0 && editPassword.length() == 0)
  69. button.setEnabled(false); //disable at app start
  70. }
  71.  
  72. @Override
  73. protected void onResume() {
  74. super.onResume();
  75.  
  76. SharedPreferences sharedPreferences = getSharedPreferences(Config.SHARED_PREF_NAME, Context.MODE_PRIVATE);
  77.  
  78. loggedIn = sharedPreferences.getBoolean(Config.LOGGEDIN_SHARED_PREF, false);
  79.  
  80. // If the value of loggedIn variable is true
  81. if(!loggedIn) {
  82.  
  83. // We will start the Courses activity
  84. Intent intent = new Intent(LoginActivity.this, CourseActivity.class);
  85. startActivity(intent);
  86. }
  87. }
  88.  
  89. private void login() {
  90.  
  91. // Get the values from the edit texts
  92. final String email = editTextEmail.getText().toString().trim();
  93. final String password = editTextPassword.getText().toString().trim();
  94.  
  95. // Creating a JSON Object request
  96. JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, Config.LOGIN_URL, null, new Response.Listener<JSONObject>() {
  97.  
  98. @Override
  99. public void onResponse(JSONObject response) {
  100. Log.d(TAG, response.toString());
  101.  
  102. // This line will not print out
  103. System.out.println(response);
  104.  
  105. try {
  106.  
  107. String json_status = response.getString("status");
  108. String message = response.getString("message");
  109.  
  110. if(json_status.equalsIgnoreCase(Config.LOGIN_SUCCESS)) {
  111. System.out.println(message);
  112. }
  113.  
  114. } catch (JSONException e) {
  115. Toast.makeText(getApplicationContext(), "Error: " + e.getMessage(), Toast.LENGTH_LONG).show();
  116. e.printStackTrace();
  117. }
  118. }
  119. },
  120. new Response.ErrorListener() {
  121. @Override
  122. public void onErrorResponse(VolleyError error) {
  123. // You can handle the error here if you want
  124. }
  125. }) {
  126. @Override
  127. protected Map<String, String> getParams() throws AuthFailureError {
  128. Map<String, String> params = new HashMap<>();
  129.  
  130. // Adding parameters to request
  131. params.put(Config.KEY_EMAIL, email);
  132. params.put(Config.KEY_PASSWORD, password);
  133.  
  134. // Return parameters
  135. return params;
  136.  
  137. }
  138. };
  139.  
  140. // Adding the string request to the queue
  141. RequestQueue requestQueue = Volley.newRequestQueue(this);
  142. requestQueue.add(jsonObjectRequest);
  143.  
  144. }
  145.  
  146. @Override
  147. public void onClick(View v) {
  148.  
  149. switch(v.getId()) {
  150. // If button Login was clicked
  151. case R.id.buttonLogin:
  152. login(); // Start login method after "Login" button is clicked
  153.  
  154. // startActivity(new Intent(this, MainActivity.class));
  155. break;
  156. }
  157. }
  158. }
  159.  
  160. <?php
  161. require_once("dbconnect.php");
  162.  
  163. // POST Variables
  164. $post_email = $_POST['email'];
  165. $post_password = $_POST['password'];
  166.  
  167. // Prepare the SQL query
  168. $stmt = $pdo->prepare("SELECT * FROM users WHERE email = :email");
  169. $stmt->execute(array(
  170. ':email' => $post_email,
  171. ));
  172.  
  173. $row = $stmt->fetch(PDO::FETCH_ASSOC);
  174.  
  175.  
  176. if($stmt->rowCount() > 0 && password_verify($post_password, $row['password']) && $row['role'] != 'staff') {
  177.  
  178. $user = array(); // Create an array for the user information
  179.  
  180. $user['id'] = $row['id'];
  181. $user['name'] = $row['name'];
  182. $user['email'] = $row['email'];
  183. $user['password'] = $row['password'];
  184. $user['role'] = $row['role'];
  185.  
  186. // echo json_encode(["message" => "success"]);
  187. echo json_encode(["status" => "success", "message" => "Successfully logged in"]); // Format the array to JSON
  188.  
  189. } else {
  190.  
  191. echo json_encode(["status" => "error", "message" => "Incorrect creditentials"]);
  192. }
  193.  
  194. // Get the values from the edit texts
  195. final String email = editTextEmail.getText().toString().trim();
  196. final String password = editTextPassword.getText().toString().trim();
  197.  
  198. Map<String, Object> params = new ArrayMap<>(2);
  199. // Adding parameters to request
  200. params.put(Config.KEY_EMAIL, email);
  201. params.put(Config.KEY_PASSWORD, password);
  202.  
  203. // Creating a JSON Object request
  204. JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, url, new JSONObject(params),
  205. new Response.Listener<JSONObject>()
  206. {
  207. @Override
  208. public void onResponse(JSONObject response)
  209. {
  210. Log.d(TAG, response.toString());
  211. // other stuff ...
  212. }
  213. },
  214. new Response.ErrorListener()
  215. {
  216. @Override
  217. public void onErrorResponse(VolleyError error)
  218. {
  219. // You can handle the error here if you want
  220. }
  221. });
  222.  
  223. // Adding the string request to the queue
  224. RequestQueue requestQueue = Volley.newRequestQueue(this);
  225. requestQueue.add(jsonObjectRequest);
Add Comment
Please, Sign In to add comment