<commit_before>package com.yidejia.app.mall.datamanage;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

import org.json.JSONException;
import org.json.JSONObject;

import com.yidejia.app.mall.MyApplication;
import com.yidejia.app.mall.net.ConnectionDetector;
import com.yidejia.app.mall.net.user.Login;
import com.yidejia.app.mall.net.user.Register;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;

public class UserDatamanage {
	
	private String TAG = UserDatamanage.class.getName();
	
	private String username;
	private String password;
	private String ip;
	private String cps;
	
	private String message;
	private boolean isSuccess = true;
	
	private Context context;
	public UserDatamanage(Context context){
		this.context = context;
	}
	/**
	 * ¼
	 * @param username
	 * @param password
	 * @param ip
	 * @return
	 */
	public boolean userLogin(String username, String password, String ip){
		this.username = username;
		this.password = password;
		this.ip = ip;
		
		boolean state = false;
		if(!ConnectionDetector.isConnectingToInternet(context)) {
			Toast.makeText(context, "δӣ״̬", Toast.LENGTH_LONG).show();
			return state;
		}
		TaskLogin taskLogin = new TaskLogin();
		try {
			state = taskLogin.execute().get();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e){
			Log.e(TAG, "login other ex");
			e.printStackTrace();
		} 
		if(!isSuccess){
			Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
		}
		return state;
	}
	
	private class TaskLogin extends AsyncTask<Void, Void, Boolean>{

		@Override
		protected Boolean doInBackground(Void... params) {
			// TODO Auto-generated method stub
			Login login = new Login();
			try {
				String httpResponse = login.getHttpResponse(username, password, ip);
				try {
					int code;
					JSONObject jsonObject = new JSONObject(httpResponse);
					code = jsonObject.getInt("code");
					String response = jsonObject.getString("response");
					if(code == 1000){
						MyApplication myApplication = (MyApplication) context.getApplicationContext();
						JSONObject responseObject = new JSONObject(response);
						String customer_id = responseObject.getString("customer_id");
						myApplication.setUserId(customer_id);
						myApplication.setPassword(responseObject.getString("password"));
						myApplication.setVip(responseObject.getString("customer_grade"));
						myApplication.setNick(responseObject.getString("customer_nick"));
						String imgUrl = responseObject.getString("avatar_path");
						myApplication.setUserHeadImg(imgUrl);
						String token = responseObject.getString("token");
						myApplication.setToken(token);
						return true;
					} if(code == 1001 || code ==1002){
						message = "ûڻ";
//						throw new UserLoginEx(message);
						isSuccess = false;<commit_msg>添加登陆成功时的提示<commit_after>package com.yidejia.app.mall.datamanage;

import java.io.IOException;
import java.util.concurrent.ExecutionException;

import org.json.JSONException;
import org.json.JSONObject;

import com.yidejia.app.mall.MyApplication;
import com.yidejia.app.mall.net.ConnectionDetector;
import com.yidejia.app.mall.net.ImageUrl;
import com.yidejia.app.mall.net.user.Login;
import com.yidejia.app.mall.net.user.Register;

import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import android.widget.Toast;

public class UserDatamanage {
	
	private String TAG = UserDatamanage.class.getName();
	
	private String username;
	private String password;
	private String ip;
	private String cps;
	
	private String message;
	private boolean isSuccess = true;
	
	private Context context;
	public UserDatamanage(Context context){
		this.context = context;
	}
	/**
	 * ¼
	 * @param username
	 * @param password
	 * @param ip
	 * @return
	 */
	public boolean userLogin(String username, String password, String ip){
		this.username = username;
		this.password = password;
		this.ip = ip;
		
		boolean state = false;
		if(!ConnectionDetector.isConnectingToInternet(context)) {
			Toast.makeText(context, "δӣ״̬", Toast.LENGTH_LONG).show();
			return state;
		}
		TaskLogin taskLogin = new TaskLogin();
		try {
			state = taskLogin.execute().get();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e){
			Log.e(TAG, "login other ex");
			e.printStackTrace();
		} 
		if(!isSuccess){
			Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
		}
		return state;
	}
	
	private class TaskLogin extends AsyncTask<Void, Void, Boolean>{

		@Override
		protected Boolean doInBackground(Void... params) {
			// TODO Auto-generated method stub
			Login login = new Login();
			try {
				String httpResponse = login.getHttpResponse(username, password, ip);
				try {
					int code;
					JSONObject jsonObject = new JSONObject(httpResponse);
					code = jsonObject.getInt("code");
					String response = jsonObject.getString("response");
					if(code == 1000){
						MyApplication myApplication = (MyApplication) context.getApplicationContext();
						JSONObject responseObject = new JSONObject(response);
						String customer_id = responseObject.getString("customer_id");
						myApplication.setUserId(customer_id);
						myApplication.setPassword(responseObject.getString("password"));
						myApplication.setVip(responseObject.getString("customer_grade"));
						myApplication.setNick(responseObject.getString("customer_nick"));
						String imgUrl = responseObject.getString("avatar_path");
						myApplication.setUserHeadImg(ImageUrl.IMAGEURL +imgUrl);
						String token = responseObject.getString("token");
						myApplication.setToken(token);
						message = "½ɹ";
						return true;
					} if(code == 1001 || code ==1002){
						message = "ûڻ";
//						throw new UserLoginEx(message);
						isSuccess = false;
{'fraction_non_alphanumeric': 0.11484502446982056, 'fraction_numerical': 0.003915171288743882, 'mean_word_length': 4.062758051197357, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '673695', 'n_tokens_mistral': 2164, 'n_tokens_neox': 1800, 'n_words': 412}