Advertisement
novyanedwin

Untitled

Jun 9th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.76 KB | None | 0 0
  1. file activity_regist.xml:
  2.  
  3. <?xml version="1.0" encoding="utf-8"?>
  4. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  5. xmlns:app="http://schemas.android.com/apk/res-auto"
  6. xmlns:tools="http://schemas.android.com/tools"
  7. android:id="@+id/activity_login"
  8. android:layout_width="match_parent"
  9. android:layout_height="match_parent"
  10. android:paddingBottom="@dimen/activity_vertical_margin"
  11. android:paddingLeft="@dimen/activity_horizontal_margin"
  12. android:paddingRight="@dimen/activity_horizontal_margin"
  13. android:paddingTop="@dimen/activity_vertical_margin"
  14. tools:context="com.example.novyan.app1.login"
  15. android:background="@color/abu"
  16. android:gravity="center">
  17.  
  18. <LinearLayout
  19. android:orientation="vertical"
  20. android:layout_width="match_parent"
  21. android:layout_height="match_parent"
  22. android:layout_alignParentTop="true"
  23. android:layout_alignParentLeft="true"
  24. android:layout_alignParentStart="true">
  25.  
  26. <ImageView
  27. android:layout_width="wrap_content"
  28. android:layout_height="192dp"
  29. app:srcCompat="@drawable/logo_lab"
  30. android:id="@+id/imageView" />
  31.  
  32. <LinearLayout
  33. android:orientation="vertical"
  34. android:layout_width="match_parent"
  35. android:layout_height="wrap_content"
  36. android:weightSum="1">
  37.  
  38. <TextView
  39. android:text="NPM"
  40. android:layout_width="wrap_content"
  41. android:layout_height="wrap_content"
  42. android:id="@+id/textView"
  43. android:textColor="@color/abucerah"
  44. android:textSize="18sp" />
  45.  
  46. <EditText
  47. android:layout_width="match_parent"
  48. android:layout_height="wrap_content"
  49. android:inputType="text"
  50. android:ems="10"
  51. android:id="@+id/fil_npm"
  52. android:textColor="@android:color/black"
  53. android:background="@android:color/background_light"
  54. android:singleLine="true"
  55. android:gravity="center"
  56. android:textSize="24sp" />
  57.  
  58. <TextView
  59. android:text="Username"
  60. android:layout_width="match_parent"
  61. android:layout_height="wrap_content"
  62. android:id="@+id/textView2"
  63. android:textColor="@color/abucerah"
  64. android:textSize="18sp" />
  65.  
  66. <EditText
  67. android:layout_width="match_parent"
  68. android:layout_height="wrap_content"
  69. android:inputType="text"
  70. android:ems="10"
  71. android:id="@+id/fil_uname"
  72. android:textColor="@android:color/black"
  73. android:background="@android:color/background_light"
  74. android:singleLine="true"
  75. android:gravity="center"
  76. android:textSize="24sp" />
  77.  
  78. <TextView
  79. android:text="Password"
  80. android:layout_width="match_parent"
  81. android:layout_height="wrap_content"
  82. android:id="@+id/textView3"
  83. android:textColor="@color/abucerah"
  84. android:textSize="18sp" />
  85.  
  86. <EditText
  87. android:layout_width="match_parent"
  88. android:layout_height="wrap_content"
  89. android:inputType="textPassword"
  90. android:ems="10"
  91. android:id="@+id/fil_pass"
  92. android:textColor="@android:color/black"
  93. android:background="@android:color/background_light"
  94. android:singleLine="true"
  95. android:gravity="center"
  96. android:textSize="24sp" />
  97.  
  98. </LinearLayout>
  99.  
  100. <LinearLayout
  101. android:orientation="vertical"
  102. android:layout_width="match_parent"
  103. android:layout_height="match_parent"
  104. android:gravity="center">
  105.  
  106. <Button
  107. android:id="@+id/button1"
  108. android:layout_height="wrap_content"
  109. android:layout_width="wrap_content"
  110. android:text="self_destruct" />
  111.  
  112.  
  113. <TextView
  114. android:text="Sudah Registrasi?"
  115. android:layout_width="wrap_content"
  116. android:layout_height="wrap_content"
  117. android:id="@+id/textView4" />
  118.  
  119. <Button
  120. android:text="Log In"
  121. android:layout_width="wrap_content"
  122. android:layout_height="wrap_content"
  123. android:id="@+id/login_btn"
  124. android:onClick="login" />
  125.  
  126. </LinearLayout>
  127.  
  128. </LinearLayout>
  129.  
  130. </RelativeLayout>
  131.  
  132. --------------------------------------------------------------------------------
  133.  
  134. file Regist.java:
  135.  
  136. package com.example.novyan.app1;
  137.  
  138. import android.content.Intent;
  139. import android.os.Bundle;
  140. import android.support.v7.app.AppCompatActivity;
  141. import android.view.View;
  142. import android.widget.Button;
  143. import android.widget.EditText;
  144. import android.widget.Toast;
  145.  
  146. public class Regist extends AppCompatActivity {
  147. EditText ETnpm,ETuname,ETpass;
  148. String npm, uname, pass, tipe;
  149.  
  150. /*@Override
  151. protected void onCreate(Bundle savedInstanceState) {
  152. super.onCreate(savedInstanceState);
  153. setContentView(R.layout.activity_regist);
  154.  
  155. }*/
  156.  
  157. protected void onCreate(Bundle savedInstanceState) {
  158. super.onCreate(savedInstanceState);
  159. setContentView(R.layout.activity_regist);
  160. ETuname = (EditText) findViewById(R.id.fil_user);
  161. ETpass = (EditText) findViewById(R.id.fil_pass);
  162. ETnpm = (EditText) findViewById(R.id.fil_npm);
  163.  
  164.  
  165. Button button = (Button) findViewById(R.id.button1);
  166.  
  167. button.setOnClickListener( new View.OnClickListener()
  168. {
  169. public void onClick (View v){
  170. next_page(v);
  171. }
  172. });
  173. }
  174.  
  175. public void masukin(){
  176. npm = ETnpm.getText().toString();
  177. uname = ETuname.getText().toString();
  178. pass = ETpass.getText().toString();
  179. }
  180.  
  181. public void next_page(View v) {
  182.  
  183. tipe = "regist";
  184. Toast.makeText(getApplicationContext(), tipe, Toast.LENGTH_LONG).show();
  185. masukin();
  186. //uname = ETuname.getText().toString();
  187. //pass = ETpass.getText().toString();
  188. //tipe = "regist";
  189.  
  190. /*BackgroundWorker bgworker = new BackgroundWorker(this);
  191. bgworker.execute(type, uname, pass, npm);*/
  192. }
  193.  
  194. /*public void daftar (View view) {
  195.  
  196.  
  197. }*/
  198.  
  199.  
  200. public void login (View view){
  201. Intent intent = new Intent(this, login.class);
  202. startActivity(intent);
  203. }
  204. }
  205.  
  206. --------------------------------------------------------------------------------
  207.  
  208.  
  209. file BackgroundWorker.java:
  210.  
  211. package com.example.novyan.app1;
  212.  
  213. import android.app.AlertDialog;
  214. import android.app.ProgressDialog;
  215. import android.content.Context;
  216. import android.os.AsyncTask;
  217.  
  218. import java.io.BufferedReader;
  219. import java.io.BufferedWriter;
  220. import java.io.IOException;
  221. import java.io.InputStream;
  222. import java.io.InputStreamReader;
  223. import java.io.OutputStream;
  224. import java.io.OutputStreamWriter;
  225. import java.net.HttpURLConnection;
  226. import java.net.URL;
  227. import java.net.URLEncoder;
  228.  
  229. /**
  230. * Created by Novyan on 6/6/2017.
  231. */
  232.  
  233. class BackgroundWorker extends AsyncTask <String,String,String> {
  234. Context context;
  235. AlertDialog ad;
  236. String result;
  237.  
  238. BackgroundWorker (Context ctx){
  239. context = ctx;
  240. }
  241. @Override
  242. protected String doInBackground(String... params) {
  243. String type = params[0];
  244. String login_url = "http://projeknovyan.net16.net/login.php";
  245. String regist_url = "http://projeknovyan.net16.net/registrasi.php";
  246. if(type.equals("login")){
  247. try {
  248. String username = params[1];
  249. String password = params[2];
  250. URL url = new URL(login_url);
  251. HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
  252. httpURLConnection.setRequestMethod("POST");
  253. httpURLConnection.setDoOutput(true);
  254. httpURLConnection.setDoInput(true);
  255. OutputStream outputStream = httpURLConnection.getOutputStream();
  256. BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
  257. String post_data = URLEncoder.encode("user_android","UTF-8")+"="+URLEncoder.encode(username,"UTF-8")+"&"
  258. +URLEncoder.encode("pass_user_anroid","UTF-8")+"="+URLEncoder.encode(password,"UTF-8");
  259. bufferedWriter.write(post_data);
  260. bufferedWriter.flush();
  261. bufferedWriter.close();
  262. InputStream inputStream = httpURLConnection.getInputStream();
  263. BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
  264. String result = "", line;
  265. while ((line = bufferedReader.readLine()) != null){
  266. result+=line;
  267. }
  268. bufferedReader.close();
  269. inputStream.close();
  270. httpURLConnection.disconnect();
  271. return result;
  272. } catch (IOException e) {
  273. e.printStackTrace();
  274. }
  275. }else {
  276. if (type.equals("regist")) {
  277. try {
  278. String username = params[1];
  279. String password = params[2];
  280. String npm = params[3];
  281. URL url = new URL(regist_url);
  282. HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
  283. httpURLConnection.setRequestMethod("POST");
  284. httpURLConnection.setDoOutput(true);
  285. httpURLConnection.setDoInput(true);
  286. OutputStream outputStream = httpURLConnection.getOutputStream();
  287. BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
  288. String post_data = URLEncoder.encode("user_android","UTF-8")+"="+URLEncoder.encode(username,"UTF-8")+"&"
  289. +URLEncoder.encode("pass_user_anroid","UTF-8")+"="+URLEncoder.encode(password,"UTF-8")+"&"
  290. +URLEncoder.encode("npm_android","UTF-8")+"="+URLEncoder.encode(npm,"UTF-8");
  291. bufferedWriter.write(post_data);
  292. bufferedWriter.flush();
  293. bufferedWriter.close();
  294. InputStream inputStream = httpURLConnection.getInputStream();
  295. BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "iso-8859-1"));
  296. String result = "", line;
  297. while ((line = bufferedReader.readLine()) != null){
  298. result+=line;
  299. }
  300. bufferedReader.close();
  301. inputStream.close();
  302. httpURLConnection.disconnect();
  303. return result;
  304. } catch (IOException e) {
  305. e.printStackTrace();
  306. }
  307. }
  308. }
  309. return null;
  310. }
  311.  
  312.  
  313. @Override
  314. protected void onPreExecute() {
  315. ad = new AlertDialog.Builder(context).create();
  316. ad.setTitle("Status");
  317. }
  318.  
  319. @Override
  320. protected void onPostExecute(String result) {
  321. ad.setMessage(result);
  322. ad.show();
  323. }
  324.  
  325. @Override
  326. protected void onProgressUpdate(String... values) {
  327. super.onProgressUpdate(values);
  328. }
  329. }
  330.  
  331. --------------------------------------------------------------------------------------------------------------------
  332.  
  333. file registrasi.php
  334.  
  335. <?php
  336. require_once "conn.php";
  337.  
  338. $key= $_POST["npm_android"];
  339. $username = $_POST["user_android"];
  340. $userpassword = $_POST["pass_user_android"];
  341. $qry_select = "select nama from mahasiswa where npm like $key";
  342. $res = mysqli_query($conn, $qry_select);
  343. if(mysqli_num_rows($res) > 0){
  344. $qry_select2 = "select uname_mhs from mahasiswa where npm like $key";
  345. $res2 = mysqli_query($conn, $qry_select2);
  346. if(mysqli_num_rows($res2) < 1){
  347. $qry = "update mahasiswa set uname_mhs = '$username', pass_mhs = '$userpassword' where npm = '$key'";
  348. if($conn->query($qry) === TRUE){
  349. echo "Registrasi Berhasil, Silahkan Login";
  350. }else{
  351. echo $conn->error;
  352. }
  353. }else{
  354. echo "User Telah Terdaftar, Registrasi Dibatalkan";
  355. }
  356. }else{
  357. echo "NPM anda tidak terdaftar";
  358. }
  359.  
  360. $conn->close();
  361. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement