I'm creating a Login using parse database in my ANDROID APP.
I have added a password reset utility manually for now,
meaning that if a user wants to reset their password they will send a notification email to the app admin by using the app itself and to the site admin
Now I want to add a function to write the new password to the parse database and send that password to the user via email automatically
If anyone knows how to, please help me
my parse class name
_User
parse column names
password , e-mail
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.parse.LogInCallback;
import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseUser;
import app.com.anew.gdg.utilities.ApplicationData;
public class MainActivity extends AppCompatActivity {
protected EditText mUsername;
protected EditText mPass;
protected Button mBtn;
TextView forgotPassword;
ApplicationData applicationData;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId("")
.server("")
.build()
);
}catch (Exception e){}
applicationData = new ApplicationData(MyApplication.getInstance());
if(applicationData.isLoggedIn()){
Intent welcomhome = new Intent(MainActivity.this, AppMain.class);
startActivity(welcomhome);
}
mUsername = (EditText) findViewById(R.id.uu);
mPass = (EditText) findViewById(R.id.pp);
mBtn = (Button) findViewById(R.id.bb);
mBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String username= mUsername.getText().toString().trim();
String password= mPass.getText().toString().trim();
ParseUser.logInInBackground(username, password, new LogInCallback() {
public void done(ParseUser user, ParseException e) {
if (user != null) {
String registeredDevice = user.getString("devicename");
String currentDevice = Build.MODEL;
if ((registeredDevice.equalsIgnoreCase("") ) || (registeredDevice == null)){
user.put("devicename", currentDevice);
user.saveInBackground();
Toast.makeText(MainActivity.this, "You have registered this app with this device!", Toast.LENGTH_LONG).show();
Intent welcomehome = new Intent(MainActivity.this, AppMain.class);
applicationData.setLogin(true);
startActivity(welcomehome);
finish();
}else{
if(currentDevice.equals(registeredDevice)){
Toast.makeText(MainActivity.this, "Welcome!", Toast.LENGTH_LONG).show();
Intent welcomehome = new Intent(MainActivity.this, AppMain.class);
applicationData.setLogin(true);
startActivity(welcomehome);
finish();
}else{
// delete registered device from database.
//user.remove("devicename");
//user.saveInBackground(); Toast.makeText(MainActivity.this, "You are using unregistered device!!", Toast.LENGTH_LONG).show();
ParseUser.logOutInBackground();
finish();
}
}
} else {
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setMessage(e.getMessage());
builder.setTitle("Sorry");
builder.setPositiveButton("ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
}
});
}
});
forgotPassword = (TextView) findViewById(R.id.forgotPassword);
forgotPassword.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String personEmail = "membership@company.com";
Intent i = new Intent(Intent.ACTION_SEND);
i.setData(Uri.parse("mailto:"));
i.setType("plain/text");
i.putExtra(Intent.EXTRA_EMAIL, new String[] {personEmail});
i.putExtra(Intent.EXTRA_SUBJECT, "Forgot Password");
i.putExtra(Intent.EXTRA_TEXT, "Hey,\nI forgot my Password Kindly Reset it.");
startActivity(i);
}
});
}
@Override
public void onBackPressed() {
super.onBackPressed();
System.exit(0);
}
}
You may want to consider this: http://docs.parseplatform.org/android/guide/#user-interface
It will help saving the need to reinvent the wheel. This coupled with the mailgun plugin should help integrate these features into your app.