登录、注册界面
主要代码
注册按钮
//注册点击
public void dregi(View view){
Intent intentlogin = new Intent();
intentlogin.setClass(SecondActivity.this,MainActivity.class);
startActivity(intentlogin);
登录按钮
//登录点击
public void dlogin(View view){
String name=mname.getText().toString();
String password=mpassword.getText().toString();
if(name.equals("")||password.equals("")){
Toast.makeText(this, "帐号或密码不能为空", Toast.LENGTH_LONG).show();
return;
}
BmobQuery
query.addWhereEqualTo("name", name);
query.addWhereEqualTo("password", password);
query.findObjects(new FindListener
@Override
public void done(List<user> arg0, BmobException e) {
// TODO Auto-generated method stub
if(e==null){
String gname=arg0.get(0).getName().toString();
String gpassword=arg0.get(0).getPassword().toString();
String name=mname.getText().toString();
String password=mpassword.getText().toString();
Toast.makeText(SecondActivity.this, gname, Toast.LENGTH_LONG).show();
if(gname.equals(name)&&gpassword.equals(password))
{
Intent seccess = new Intent();
seccess.setClass(SecondActivity.this, ThridActivity.class);
startActivity(seccess);
}
}
else{
Toast.makeText(SecondActivity.this, "帐号或密码有误", Toast.LENGTH_LONG).show();
}
注册功能的实现:
//点击注册
public void zhuce(View view){
String name=mname.getText().toString();
String password=mpassword.getText().toString();
String number=mnumber.getText().toString();
String verify=mverify.getText().toString();
if(name.equals("")||password.equals(""))
{
Toast.makeText(this, "帐号或密码不能为空", Toast.LENGTH_LONG).show();
return;
}
if(name.length()<6)
{
Toast.makeText(this, "帐号小于6位", Toast.LENGTH_LONG).show();
return;
}
if(verify.length()==0)
{
Toast.makeText(this, "验证码不能为空", Toast.LENGTH_LONG).show();
return;
}
if(number.length()==0)
{
Toast.makeText(this, "手机号不能为空", Toast.LENGTH_LONG).show();
return;
}
if(number.length()!=11)
{
Toast.makeText(this, "请输入11位有效号码", Toast.LENGTH_LONG).show();
return;
}
BmobSMS.verifySmsCode(this, number, verify, new VerifySMSCodeListener() {
@Override
public void done(cn.bmob.sms.exception.BmobException e) {
// TODO Auto-generated method stub
if (e == null) {
Toast.makeText(MainActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
//验证码正确 添加用户信息
String name=mname.getText().toString();
String password=mpassword.getText().toString();
user User=new user();
User.setName(name);
User.setPassword(password);
User.save(new SaveListener<String>() {
@Override
public void done(String arg0, BmobException arg1) {
// TODO Auto-generated method stub
if(arg1==null){
return;
}else{
return;
}
}
});
Intent intent2 = new Intent();
intent2.setClass(MainActivity.this, SecondActivity.class);
MainActivity.this.startActivity(intent2);
}
else {
Toast.makeText(MainActivity.this, "验证码错误", Toast.LENGTH_SHORT).show();
}
}