Login登录


//////////////////////////////////////////登录
package com.example.app.Activity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.example.app.Bean.LoginBean;
import com.example.app.Bean.LunboBean;
import com.example.app.MainActivity;
import com.example.app.Persener.GetPersener;
import com.example.app.R;
import com.example.app.jiekou.Iview;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

public class LoginActivity extends AppCompatActivity implements Iview{

    private EditText phone;
    private EditText password;
    private TextView kszc;
    private Button dengl;
    private GetPersener getPersener;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        phone =(EditText)findViewById(R.id.phone);//手机号
        password =(EditText)findViewById(R.id.password);//密码
        kszc =(TextView) findViewById(R.id.kszc);//快速注册
        dengl =(Button)findViewById(R.id.dengl);
        //实例化P层
        getPersener = new GetPersener();
        getPersener.attach(this);
        //登录
        dengl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //获取输入的密码和手机号
                String phone1 = phone.getText().toString().trim();
                String password1 = password.getText().toString().trim();

                if( panduan(phone1,password1)){
                    //请求轮播数据
                    Map<String, String> map = new HashMap<>();
                    map.put("mobile",phone1);
                    map.put("password",password1);
                    getPersener.get("http://120.27.23.105/user/login",map, LoginBean.class,"登录");
                }
            }
        });

        //点击快速注册的跳转页面
        kszc.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(LoginActivity.this, ZhuceActivity.class);
                startActivity(intent);
            }
        });
    }


    @Override
    public void onSuccess(Object o, String tag) {
        if (tag=="登录"){
            LoginBean bean=(LoginBean)o;
            String msg = bean.getMsg();
            if(msg.equals("天呢!用户不存在")){
                Toast.makeText(LoginActivity.this,"没有该用户",Toast.LENGTH_SHORT).show();
            }else if(msg.equals("登录成功")){
                Toast.makeText(LoginActivity.this,"登录成功",Toast.LENGTH_SHORT).show();
                finish();
            }else if(msg.equals("天呢!密码错误")){
                Toast.makeText(LoginActivity.this,"密码不正确",Toast.LENGTH_SHORT).show();
            }
        }
    }

    @Override
    public void onFailed(Exception e) {

    }


    public Boolean panduan(String username,String userpsd) {
        //正则表达式
        String regex = "^1[3|4|5|7|8]\\d{9}";

        if (TextUtils.isEmpty(username) || TextUtils.isEmpty(userpsd)) {
            Toast.makeText(this, "账号或密码是空", Toast.LENGTH_SHORT).show();
            return false;
        } else {
            if (!Pattern.matches(regex, username)) {//不加!是true  加了是false
                Toast.makeText(this, "手机号格式错误", Toast.LENGTH_SHORT).show();
                return false;
            }
        }
        if(userpsd.length()<6){
            Toast.makeText(this, "密码小于六位数", Toast.LENGTH_SHORT).show();
            return false;
        }
        return  true;
    }
}



///////////////////////////////////////////////注册
package com.example.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.example.app.Bean.LoginBean;
import com.example.app.Bean.ZhuceBean;
import com.example.app.Persener.GetPersener;
import com.example.app.R;
import com.example.app.jiekou.Iview;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Pattern;

public class ZhuceActivity extends AppCompatActivity implements Iview{

    private EditText phone;
    private EditText password;
    private Button zhuce;
    private GetPersener getPersener;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zhuce);
        phone =(EditText)findViewById(R.id.phone);//手机号
        password =(EditText)findViewById(R.id.password);//密码
        zhuce =(Button)findViewById(R.id.zhuce);
        //实例化P层
        getPersener = new GetPersener();
        getPersener.attach(this);
        //注册
        zhuce.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //获取输入的密码和手机号
                String phone1 = phone.getText().toString().trim();
                String password1 = password.getText().toString().trim();
                if( panduan(phone1,password1)){
                    //请求轮播数据
                    Map<String, String> map = new HashMap<>();
                    map.put("mobile",phone1);
                    map.put("password",password1);
                    getPersener.get("http://120.27.23.105/user/reg",map, ZhuceBean.class,"注册");
                }
            }
        });
    }

    public Boolean panduan(String username,String userpsd) {
        //正则表达式
        String regex = "^1[3|4|5|7|8]\\d{9}";

        if (TextUtils.isEmpty(username) || TextUtils.isEmpty(userpsd)) {
            Toast.makeText(this, "账号或密码是空", Toast.LENGTH_SHORT).show();
            return false;
        } else {
            if (!Pattern.matches(regex, username)) {//不加!是true  加了是false
                Toast.makeText(this, "手机号格式错误", Toast.LENGTH_SHORT).show();
                return false;
            }
        }
        if(userpsd.length()<6){
            Toast.makeText(this, "密码不能小于六位数", Toast.LENGTH_SHORT).show();
            return false;
        }
        return  true;
    }



    @Override
    public void onSuccess(Object o, String tag) {
        if (tag=="注册"){
            ZhuceBean bean=(ZhuceBean)o;
            String msg = bean.getMsg();
            if(msg.equals("天呢!用户已注册")){
                Toast.makeText(ZhuceActivity.this,"该用户已被注册,请重新注册",Toast.LENGTH_SHORT).show();
            }else if(msg.equals("注册成功")){
                Toast.makeText(ZhuceActivity.this,"注册成功",Toast.LENGTH_SHORT).show();
                finish();
            }
        }
    }

    @Override
    public void onFailed(Exception e) {

    }
}


////////////////////////////////////////////////登录密码
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:layout_gravity="center_horizontal"
        android:textSize="20dp"
        android:layout_marginTop="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="京东登录" />



    <LinearLayout
        android:layout_marginTop="20dp"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    <TextView
        android:id="@+id/tv1"
        android:text="账号:"
        android:textSize="20dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    <EditText
        android:id="@+id/phone"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入手机号"/>
    </LinearLayout>

    <LinearLayout
        android:layout_marginTop="20dp"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:textSize="20dp"
            android:id="@+id/tv2"
            android:text="密码:"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    <EditText
        android:id="@+id/password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="请输入密码"/>
    </LinearLayout>
    <Button
        android:layout_marginTop="20dp"
        android:id="@+id/dengl"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="登录"/>

    <LinearLayout
        android:layout_marginTop="20dp"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/kszc"
            android:text="手机快速注册"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        <TextView
            android:id="@+id/wangjmm"
            android:text="忘记密码"
            android:layout_marginLeft="260dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
    </LinearLayout>
</LinearLayout>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值