解析数据库用户密码重置

时间:2017-05-03 06:16:28

标签: java android database parse-server

我在我的ANDROID APP中使用解析数据库创建了一个登录 我现在手动添加了密码重置实用程序,
意味着如果用户想要重置密码,他们会通过使用应用程序本身和网站管理员向应用管理员发送通知电子邮件

现在我想添加一个函数来将新密码写入解析数据库和 通过电子邮件自动将该密码发送给用户

如果有人知道怎么做,请帮帮我

我的解析班级名称

_User

解析列名

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);
        }

    }

1 个答案:

答案 0 :(得分:1)

您可能需要考虑这个问题:http://docs.parseplatform.org/android/guide/#user-interface

这将有助于节省重新发明轮子的需要。这与mailgun插件相结合应该有助于将这些功能集成到您的应用程序中。