Advertisement
Guest User

Untitled

a guest
May 20th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.31 KB | None | 0 0
  1. package com.smartfanssolutions.riotpointsjob1;
  2.  
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.support.v4.app.ActivityCompat;
  6. import android.util.Log;
  7. import android.view.MenuItem;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.EditText;
  11. import android.widget.Toast;
  12.  
  13. import com.android.volley.Request;
  14. import com.android.volley.RequestQueue;
  15. import com.android.volley.Response;
  16. import com.android.volley.VolleyError;
  17.  
  18. import org.json.JSONObject;
  19.  
  20. import java.util.HashMap;
  21. import java.util.Map;
  22. import java.util.Timer;
  23. import java.util.TimerTask;
  24.  
  25. import com.android.volley.toolbox.StringRequest;
  26. import com.android.volley.toolbox.Volley;
  27. import com.smartfanssolutions.riotpointsjob1.app.App;
  28. import com.smartfanssolutions.riotpointsjob1.common.ActivityBase;
  29. import com.smartfanssolutions.riotpointsjob1.util.CustomRequest;
  30. import com.smartfanssolutions.riotpointsjob1.util.Helper;
  31.  
  32. public class SignupActivity extends ActivityBase {
  33.  
  34.  
  35. EditText signupUsername, signupFullname, signupPassword, signupEmail, signupReferrer;
  36. Button signupJoinBtn;
  37.  
  38. private String username, fullname, password, email , referrercode ;
  39. private PrefManager prf;
  40. private boolean referrerExisting = false, isReferrerCheating=false;
  41. public Timer AdTimer;
  42.  
  43. @Override
  44. protected void onCreate(Bundle savedInstanceState) {
  45. super.onCreate(savedInstanceState);
  46. setContentView(R.layout.activity_sign_up);
  47.  
  48.  
  49. getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  50. getSupportActionBar().setHomeButtonEnabled(true);
  51.  
  52. signupUsername = (EditText) findViewById(R.id.signupUsername);
  53. signupFullname = (EditText) findViewById(R.id.signupFullname);
  54. signupPassword = (EditText) findViewById(R.id.signupPassword);
  55. signupEmail = (EditText) findViewById(R.id.signupEmail);
  56. signupReferrer = (EditText) findViewById(R.id.signupReferrer);
  57.  
  58. signupJoinBtn = (Button) findViewById(R.id.signupJoinBtn);
  59.  
  60. signupJoinBtn.setOnClickListener(new View.OnClickListener() {
  61. @Override
  62. public void onClick(View v) {
  63.  
  64. username = signupUsername.getText().toString();
  65. fullname = signupFullname.getText().toString();
  66. password = signupPassword.getText().toString();
  67. email = signupEmail.getText().toString();
  68. referrercode = signupReferrer.getText().toString();
  69.  
  70. check_referrer(username,referrercode);
  71. if (verifyRegForm()) {
  72.  
  73. if (App.getInstance().isConnected()) {
  74.  
  75. showpDialog();
  76.  
  77. CustomRequest jsonReq = new CustomRequest(Request.Method.POST, METHOD_ACCOUNT_SIGNUP, null,
  78. new Response.Listener<JSONObject>() {
  79. @Override
  80. public void onResponse(JSONObject response) {
  81.  
  82. Log.e("Profile", "Malformed JSON: \"" + response.toString() + "\"");
  83.  
  84. if (App.getInstance().authorize(response)) {
  85.  
  86. Intent i = new Intent(getApplicationContext(), MainActivity.class);
  87. startActivity(i);
  88.  
  89. ActivityCompat.finishAffinity(SignupActivity.this);
  90.  
  91. AdTimer = new Timer();
  92.  
  93. // Prepare an Interstitial Ad Listener
  94. // Call displayInterstitial() function with timer
  95. if (AdTimer != null) {
  96. AdTimer.schedule(new TimerTask() {
  97. @Override
  98. public void run() {
  99. runOnUiThread(new Runnable() {
  100. @Override
  101. public void run() {
  102.  
  103. Toast.makeText(SignupActivity.this,"setting the referrer",Toast.LENGTH_SHORT).show();
  104.  
  105. }
  106. });
  107. }
  108. }, 4000);
  109. }
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116. } else {
  117.  
  118. switch (App.getInstance().getErrorCode()) {
  119.  
  120. case 300 : {
  121.  
  122. signupUsername.setError(getString(R.string.error_login_taken));
  123. break;
  124. }
  125.  
  126. case 301 : {
  127.  
  128. signupEmail.setError(getString(R.string.error_email_taken));
  129. break;
  130. }
  131.  
  132. default: {
  133.  
  134. Log.e("Profile", "Could not parse malformed JSON: \"" + response.toString() + "\"");
  135. break;
  136. }
  137. }
  138. }
  139.  
  140. hidepDialog();
  141. }
  142. }, new Response.ErrorListener() {
  143. @Override
  144. public void onErrorResponse(VolleyError error) {
  145.  
  146. Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG).show();
  147. Log.e("Profile", "Malformed JSON: \"" + error.getMessage() + "\"");
  148.  
  149. hidepDialog();
  150. }
  151. }) {
  152.  
  153. @Override
  154. protected Map<String, String> getParams() {
  155. Map<String, String> params = new HashMap<String, String>();
  156. params.put("username", username);
  157. params.put("fullname", fullname);
  158. params.put("password", password);
  159. params.put("email", email);
  160. params.put("clientId", CLIENT_ID);
  161.  
  162. return params;
  163. }
  164. };
  165.  
  166. App.getInstance().addToRequestQueue(jsonReq);
  167.  
  168. } else {
  169.  
  170. Toast.makeText(getApplicationContext(), R.string.msg_network_error, Toast.LENGTH_SHORT).show();
  171. }
  172. }
  173. }
  174. });
  175.  
  176. }
  177.  
  178. // check the response
  179. void check_referrer( String referral, String referrer) {
  180.  
  181.  
  182. String awr = Config.Base_Url + "get/checkref.php";
  183.  
  184.  
  185. final String v1 = "1"; // OK
  186. final String v0 = "0"; // The referrer is not existing
  187. final String v2 = "2"; // cheating
  188. StringRequest stringRequest = new StringRequest(Request.Method.POST, awr,
  189. new Response.Listener<String>() {
  190. @Override
  191. public void onResponse(String response) {
  192. if (response.intern() == v1.intern()) {
  193.  
  194. referrerExisting = true;
  195.  
  196. }
  197. if (response.intern() == v0.intern()) {
  198. referrerExisting = false;
  199.  
  200.  
  201. }
  202. if (response.intern() == v2.intern()) {
  203. isReferrerCheating = true;
  204.  
  205.  
  206. }
  207.  
  208. }
  209. },
  210. new Response.ErrorListener() {
  211. @Override
  212. public void onErrorResponse(VolleyError error) {
  213. }
  214. }) {
  215. @Override
  216. protected Map<String,String> getParams(){
  217. Map<String,String> params = new HashMap<String, String>();
  218. params.put("user",username);
  219. params.put("ref", referrercode);
  220. return params;
  221. }
  222.  
  223.  
  224. };
  225.  
  226. RequestQueue requestQueue = Volley.newRequestQueue(this);
  227. requestQueue.add(stringRequest);
  228.  
  229. }
  230.  
  231.  
  232.  
  233.  
  234.  
  235. public Boolean verifyRegForm() {
  236.  
  237. signupUsername.setError(null);
  238. signupFullname.setError(null);
  239. signupPassword.setError(null);
  240. signupEmail.setError(null);
  241. signupReferrer.setError(null);
  242.  
  243. Helper helper = new Helper();
  244.  
  245. if (username.length() == 0) {
  246.  
  247. signupUsername.setError(getString(R.string.error_field_empty));
  248.  
  249. return false;
  250. }
  251.  
  252. if (username.length() < 5) {
  253.  
  254. signupUsername.setError(getString(R.string.error_small_username));
  255.  
  256. return false;
  257. }
  258.  
  259. if (!helper.isValidLogin(username)) {
  260.  
  261. signupUsername.setError(getString(R.string.error_wrong_format));
  262.  
  263. return false;
  264. }
  265.  
  266. if (fullname.length() == 0) {
  267.  
  268. signupFullname.setError(getString(R.string.error_field_empty));
  269.  
  270. return false;
  271. }
  272.  
  273. if (password.length() == 0) {
  274.  
  275. signupPassword.setError(getString(R.string.error_field_empty));
  276.  
  277. return false;
  278. }
  279.  
  280. if (password.length() < 6) {
  281.  
  282. signupPassword.setError(getString(R.string.error_small_password));
  283.  
  284. return false;
  285. }
  286.  
  287. if (!helper.isValidPassword(password)) {
  288.  
  289. signupPassword.setError(getString(R.string.error_wrong_format));
  290.  
  291. return false;
  292. }
  293.  
  294. if (email.length() == 0) {
  295.  
  296. signupEmail.setError(getString(R.string.error_field_empty));
  297.  
  298. return false;
  299. }
  300. if (email.length() == 0) {
  301.  
  302. signupEmail.setError(getString(R.string.error_field_empty));
  303.  
  304. return false;
  305. }
  306. if (email.length() == 0) {
  307.  
  308. signupEmail.setError(getString(R.string.error_field_empty));
  309.  
  310. return false;
  311. }
  312. // verif username == referrer
  313. if (referrercode.equals(username)) {
  314.  
  315. signupReferrer.setError(getString(R.string.error_Referall_signup));
  316.  
  317. return false;
  318. }
  319.  
  320.  
  321. // verif Referrer Existing
  322. if (referrerExisting==false) {
  323.  
  324. signupReferrer.setError(getString(R.string.error_Referall_signup_NotExisting));
  325.  
  326. return false;
  327. }
  328.  
  329. // verif user & Referrer cheating
  330. if (isReferrerCheating == true) {
  331.  
  332. signupReferrer.setError(getString(R.string.error_Referall_signup_Cheating));
  333.  
  334. return false;
  335. }
  336.  
  337.  
  338.  
  339. if (!helper.isValidEmail(email)) {
  340.  
  341. signupEmail.setError(getString(R.string.error_wrong_format));
  342.  
  343. return false;
  344. }
  345.  
  346. return true;
  347. }
  348.  
  349. @Override
  350. public void onBackPressed(){
  351.  
  352. finish();
  353. }
  354.  
  355. @Override
  356. public boolean onOptionsItemSelected(MenuItem item) {
  357. // Handle action bar item clicks here. The action bar will
  358. // automatically handle clicks on the Home/Up button, so long
  359. // as you specify a parent activity in AndroidManifest.xml.
  360. switch (item.getItemId()) {
  361.  
  362. case android.R.id.home: {
  363.  
  364. finish();
  365. return true;
  366. }
  367.  
  368. default: {
  369.  
  370. return super.onOptionsItemSelected(item);
  371. }
  372. }
  373. }
  374. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement