Advertisement
Guest User

Untitled

a guest
Dec 14th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.44 KB | None | 0 0
  1. public class Login extends AppCompatActivity {
  2. TextView tvsesion;
  3. private EditText email,password;
  4. private Button sign_in_register;
  5. private RequestQueue requestQueue;
  6. private static final String URL = "http://xxxxxxxxxx/WebService/user_control.php";
  7. private StringRequest request;
  8. Context ctx;
  9.  
  10. @Override
  11. protected void onCreate(Bundle savedInstanceState) {
  12. super.onCreate(savedInstanceState);
  13. setContentView(R.layout.activity_login);
  14. ctx=this;
  15.  
  16.  
  17. Toolbar toolbar = (Toolbar)findViewById(R.id.toolbar);
  18. setSupportActionBar(toolbar);
  19.  
  20. tvsesion = (TextView)findViewById(R.id.tvsesion);
  21. email = (EditText)findViewById(R.id.txusuario);
  22. password = (EditText)findViewById(R.id.txpass);
  23. sign_in_register = (Button) findViewById(R.id.login);
  24.  
  25. comprobarPreferencias();
  26.  
  27. String font_path = "font/Harabara Mais Demo.otf";
  28. Typeface TF = Typeface.createFromAsset(getAssets(),font_path);
  29. tvsesion.setTypeface(TF);
  30.  
  31. requestQueue = Volley.newRequestQueue(this);
  32.  
  33.  
  34. sign_in_register.setOnClickListener(new View.OnClickListener() {
  35. @Override
  36. public void onClick(View view) {
  37. final String nombre = email.getText().toString();
  38. String contraseña = password.getText().toString();
  39.  
  40. PreferenciasFragment.setString(ctx, PreferenciasFragment.getKeyNombreEd(), nombre);
  41. PreferenciasFragment.setString(ctx, PreferenciasFragment.getKeyContraseñaEd(), contraseña);
  42.  
  43. request = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
  44. @Override
  45. public void onResponse(String response) {
  46.  
  47. try {
  48. JSONObject jsonObject = new JSONObject(response);
  49. if(jsonObject.names().get(0).equals("success")){
  50. Toast.makeText(getApplicationContext(),"CORRECTO!"+jsonObject.getString("success"),Toast.LENGTH_SHORT).show();
  51. startActivity(new Intent(getApplicationContext(),Drawer.class));
  52. }
  53. else {
  54. Toast.makeText(getApplicationContext(), "Error:" +jsonObject.getString("error"), Toast.LENGTH_SHORT).show();
  55. }
  56.  
  57. } catch (JSONException e) {
  58. e.printStackTrace();
  59. }
  60.  
  61.  
  62. }
  63. }, new Response.ErrorListener() {
  64. @Override
  65. public void onErrorResponse(VolleyError error) {
  66.  
  67. }
  68. }){
  69. @Override
  70. protected Map<String, String> getParams() throws AuthFailureError {
  71. HashMap<String,String> hashMap = new HashMap<String, String>();
  72. hashMap.put("email",email.getText().toString());
  73. hashMap.put("password",password.getText().toString());
  74.  
  75. return hashMap;
  76. }
  77. };
  78.  
  79. requestQueue.add(request);
  80. }
  81. });
  82. }
  83.  
  84. <?php
  85. include_once 'connection.php';
  86. class User {
  87.  
  88. private $db;
  89. private $connection;
  90.  
  91. function __construct() {
  92. $this -> db = new DB_Connection();
  93. $this -> connection = $this->db->getConnection();
  94. }
  95.  
  96. public function does_user_exist($email,$password)
  97. {
  98. $query = "Select * from usuarios where usuario='$email' and contrasena = '$password' ";
  99. $result = mysqli_query($this->connection, $query);
  100. if(mysqli_num_rows($result)>0){
  101. $json['success'] = ' Bienvenido '.$email;
  102. echo json_encode($json);
  103.  
  104. mysqli_close($this -> connection);
  105. }
  106. else{
  107. $query = "insert into USERS (email, password) values ( '$email','$password')";
  108. $inserted = mysqli_query($this -> connection, $query);
  109. if($inserted == 1 ){
  110. $json['success'] = 'Acount created';
  111. }else{
  112. $json['error'] = ' Usuaio o Contraseña incorrectos';
  113. }
  114. echo json_encode($json);
  115. mysqli_close($this->connection);
  116. }
  117.  
  118. }
  119.  
  120.  
  121. }
  122.  
  123.  
  124. $user = new User();
  125. if(isset($_POST['email'],$_POST['password'])) {
  126. $email = $_POST['email'];
  127. $password = $_POST['password'];
  128.  
  129. if(!empty($email) && !empty($password)){
  130.  
  131. $encrypted_password = md5($password);
  132. $user-> does_user_exist($email,$password);
  133.  
  134. }else{
  135. echo json_encode("you must type both inputs");
  136. }
  137.  
  138. }
  139.  
  140. public class FragmentNuevas extends Fragment {
  141.  
  142. private OnFragmentInteractionListener mListener;
  143. ArrayList<Product> arrayList;
  144. ListView lv;
  145. ProgressDialog pdialog = null;
  146. Context context = null;
  147.  
  148. public FragmentNuevas() {
  149. // Required empty public constructor
  150. }
  151.  
  152.  
  153. @Override
  154. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  155. Bundle savedInstanceState) {
  156. View view = inflater.inflate(R.layout.fragment_fragment_nuevas, container, false);
  157.  
  158. lv = (ListView)view.findViewById(R.id.listView);
  159. arrayList = new ArrayList<>();
  160. context = getActivity();
  161.  
  162. getActivity().runOnUiThread(new Runnable() {
  163. @Override
  164. public void run() {
  165. pdialog = ProgressDialog.show(context, "", "Buscando Noticias...", true);
  166. new ReadJSON().execute("http://xxxxxxxxxx/WebService/consultanuevas.php");
  167. }
  168. });
  169.  
  170. /*lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  171. @Override
  172. public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
  173. Product selectedProduct = arrayList.get(position);
  174.  
  175. Intent intent = new Intent(getActivity().getApplicationContext(), Nuevas.class);
  176. intent.putExtra("nombre", selectedProduct.getName());
  177. intent.putExtra("fecha", selectedProduct.getFecha());
  178. intent.putExtra("observaciones", selectedProduct.getPrice());
  179. intent.putExtra("folio", selectedProduct.getImage());
  180. startActivity(intent);
  181. }
  182. });*/
  183.  
  184. // Inflate the layout for this fragment
  185. return view;
  186. }
  187.  
  188. class ReadJSON extends AsyncTask<String, Integer, String> {
  189. @Override
  190. protected String doInBackground(String... params) {
  191. return readURL(params[0]);
  192. }
  193. @Override
  194. protected void onPostExecute(String content) {
  195.  
  196. pdialog.dismiss();
  197. try {
  198. JSONArray jsonarray = new JSONArray(content);
  199. for(int i =0;i<jsonarray.length(); i++){
  200. JSONObject productObject = jsonarray.getJSONObject(i);
  201. arrayList.add(new Product(
  202. productObject.getString("nombre"),
  203. productObject.getString("observaciones"),
  204. productObject.getString("fecha"),
  205. productObject.getString("folio"),
  206. productObject.getString("lugar"),
  207. productObject.getString("estado"),
  208. productObject.getString("asunto")
  209.  
  210. ));
  211. }
  212. } catch (JSONException e) {
  213. e.printStackTrace();
  214. }
  215. CustomListAdapter adapter = new CustomListAdapter(
  216. getActivity(), R.layout.custom_list_layout, arrayList
  217. );
  218. lv.setAdapter(adapter);
  219. }
  220. }
  221.  
  222. private static String readURL(String theUrl) {
  223. StringBuilder content = new StringBuilder();
  224. try {
  225. // create a url object
  226. URL url = new URL(theUrl);
  227. // create a urlconnection object
  228. URLConnection urlConnection = url.openConnection();
  229. // wrap the urlconnection in a bufferedreader
  230. BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));
  231. String line;
  232. // read from the urlconnection via the bufferedreader
  233. while ((line = bufferedReader.readLine()) != null) {
  234. content.append(line + "n");
  235. }
  236. bufferedReader.close();
  237. } catch (Exception e) {
  238. e.printStackTrace();
  239. }
  240. return content.toString();
  241. }
  242.  
  243. // TODO: Rename method, update argument and hook method into UI event
  244. public void onButtonPressed(Uri uri) {
  245. if (mListener != null) {
  246. mListener.onFragmentInteraction(uri);
  247. }
  248. }
  249.  
  250. @Override
  251. public void onAttach(Context context) {
  252. super.onAttach(context);
  253. if (context instanceof OnFragmentInteractionListener) {
  254. mListener = (OnFragmentInteractionListener) context;
  255. } else {
  256. throw new RuntimeException(context.toString()
  257. + " must implement OnFragmentInteractionListener");
  258. }
  259. }
  260.  
  261. @Override
  262. public void onDetach() {
  263. super.onDetach();
  264. mListener = null;
  265. }
  266.  
  267. /**
  268. * This interface must be implemented by activities that contain this
  269. * fragment to allow an interaction in this fragment to be communicated
  270. * to the activity and potentially other fragments contained in that
  271. * activity.
  272. * <p>
  273. * See the Android Training lesson <a href=
  274. * "http://developer.android.com/training/basics/fragments/communicating.html"
  275. * >Communicating with Other Fragments</a> for more information.
  276. */
  277. public interface OnFragmentInteractionListener {
  278. // TODO: Update argument type and name
  279. void onFragmentInteraction(Uri uri);
  280. }
  281.  
  282. <?php
  283. link=mysqli_connect("localhost","xxxxxx","xxxxx","xxxxxxxx") or die("Error en la conexion" . mysqli_error($link));
  284.  
  285. $resultado = mysqli_query($link,"SELECT * FROM solicitudes WHERE estado = 'Pendiente' ORDER BY folio DESC");
  286. while ($row = mysqli_fetch_assoc($resultado)) {
  287. $arr[] = $row;
  288.  
  289. }
  290.  
  291. echo json_encode($arr);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement