我必须在我的应用程序中添加忘记密码。我必须先在对话框中发送电子邮件,该对话框将用于检查数据库中的相应密码并在通知中显示密码。
public class OwnerLoginActivity extends AppCompatActivity {
EditText txtlogin;
EditText txtpassword;
TextView lblforgotpassword;
Button btnlogin;
Button btnregister;
MyDatabase database;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_owner_login);
txtlogin=(EditText)findViewById(R.id.txtlogin);
txtpassword=(EditText)findViewById(R.id.txtpassword);
btnlogin=(Button)findViewById(R.id.btnlogin);
btnregister=(Button)findViewById(R.id.btnregister);
lblforgotpassword=(TextView)findViewById(R.id.lblforgotpassword);
database=new MyDatabase(OwnerLoginActivity.this);
lblforgotpassword.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(OwnerLoginActivity.this, "forgot password", Toast.LENGTH_SHORT).show();
forgotPassword();
}
});
btnlogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
checkLogin();
}
});
btnregister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(OwnerLoginActivity.this, "Registered Button Clicked", Toast.LENGTH_SHORT).show();
Intent obj=new Intent(OwnerLoginActivity.this,OwnerRegistrationActivity.class);
startActivity(obj);
finish();
}
});}
public void checkLogin() {
AndroidNetworking.post("http://192.168.43.38/internship_project/android_web_services/login.php")
.addBodyParameter("email",txtlogin.getText().toString())
.addBodyParameter("password",txtpassword.getText().toString()).setTag("Login").setPriority(Priority.MEDIUM)
.build()
.getAsJSONObject(new JSONObjectRequestListener() {
@Override
public void onResponse(JSONObject response) {
System.out.println(response.toString());
try {
if(response.getString("success").equals("1")){
Toast.makeText(OwnerLoginActivity.this, response.getString("message"), Toast.LENGTH_SHORT).show();
Intent intent=new Intent(OwnerLoginActivity.this, ActDashboard.class);
startActivity(intent);
}
else
Toast.makeText(OwnerLoginActivity.this, response.getString("message"), Toast.LENGTH_SHORT).show();
} catch (JSONException e) {
e.printStackTrace();
}
}
@Override
public void onError(ANError anError) {
System.out.println(anError.toString());
Toast.makeText(OwnerLoginActivity.this, "Server time out please try again later", Toast.LENGTH_SHORT).show();
}
});
}
public void forgotPassword() {
AlertDialog.Builder builder=new AlertDialog.Builder(this);
LayoutInflater inflater=this.getLayoutInflater();
final View dialogview=inflater.inflate(R.layout.custom_dialog,null);
builder.setView(dialogview);
final EditText edt=(EditText)dialogview.findViewById(R.id.email);
builder.setTitle("Forgot password?");
builder.setMessage("Enter your email id");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
AlertDialog b=builder.create();
b.show();
}
}
我已经在onClick上添加了警告框,但问题是我不知道如何从数据库中获取密码。我是否必须在forgotPassword方法中添加Android网络?并为其创建单独的PHP文件?
编辑:我在我的程序中做了android网络,并在其中调用了通知方法(我为警报框和通知制作了两个单独的方法,并为Android网络提供了不同的方法)。我在alert box方法中调用了网络方法,并在网络中调用了密码方法。它显示了警告框,但密码通知不起作用。它给出了JSON对象错误
答案 0 :(得分:0)
您必须创建forgot.php文件
从数据库获取密码 并以JSON格式传递该密码