所以我是新手解析,我正在尝试实现一个简单的登录功能。
我正在使用此代码
ParseUser newUser = new ParseUser();
newUser.setUsername(userName);
newUser.setPassword(passwordFirst);
newUser.signUpInBackground(new SignUpCallback() {
@Override
public void done(com.parse.ParseException e) {
if (e == null) {
AppUtils.toast(getApplicationContext(),"SUCCESS");
finish();
} else {
AppUtils.log(e.toString());
}
}
});
此代码确实创建了我可以在浏览器上看到的用户,但它没有保存密码,因此我永远无法登录。可能是什么问题?有什么建议吗?
正如我所说,用户是在浏览器中创建的,但密码字段仍未定义(未编辑),因此我无法登录。
感谢。
编辑:
EditText editText_userName;
EditText editText_passwordFirst;
EditText editText_passwordSecond;
CheckBox checkBox_terms;
Button button_signUp;
Button button_cancel;
String userName;
String passwordFirst;
String passwordSecond;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity__sign_up);
//UI INIT
editText_userName=(EditText)findViewById(R.id.editText_username);
editText_passwordFirst=(EditText)findViewById(R.id.editText_passwordFirst);
editText_passwordSecond=(EditText)findViewById(R.id.editText_passwordSecond);
button_signUp = (Button)findViewById(R.id.button_signup);
button_cancel = (Button)findViewById(R.id.button_cancel);
checkBox_terms = (CheckBox)findViewById(R.id.checkBox_acceptTerms);
button_signUp.setOnClickListener(this);
button_cancel.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_activity__sign_up, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.button_signup:
passwordFirst = editText_passwordFirst.getText().toString();
passwordSecond = editText_passwordSecond.getText().toString();
userName = editText_userName.getText().toString().trim();
if(!passwordFirst.equals(passwordSecond)){
AppUtils.toast(getApplicationContext(),"Passwords do not match");
break;
}
if(!checkBox_terms.isChecked()) {
AppUtils.toast(getApplicationContext(),"Terms have not been accepted");
break;
}
ParseUser newUser = new ParseUser();
newUser.setUsername(userName);
newUser.setPassword(passwordFirst);
newUser.signUpInBackground(new SignUpCallback() {
@Override
public void done(com.parse.ParseException e) {
if (e == null) {
AppUtils.toast(getApplicationContext(),"SUCCESS");
finish();
} else {
AppUtils.log(e.toString());
}
}
});
// this.finish();
break;
case R.id.button_cancel:
this.finish();
break;
case R.id.button_showTerms:
break;
}
}
}