Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何创建唯一用户名并从WAMS检索数据_Android_Azure Mobile Services - Fatal编程技术网

Android 如何创建唯一用户名并从WAMS检索数据

Android 如何创建唯一用户名并从WAMS检索数据,android,azure-mobile-services,Android,Azure Mobile Services,我正在尝试使用WindowsAzure移动服务作为数据库进行登录注册页面。我有一个问题,当我注册为用户时,我可以用两个相同的用户名注册。是否可以使用户名唯一,这样我就不会有重复的用户名。我还想知道如何检索WAMS中的数据,以便能够检查用户名和密码以使登录部分正常工作。FYI btn1用于登录,btn2用于注册。一定要帮我做什么。谢谢 LoginRegister.java package mp.memberuse; import java.net.MalformedURLException;

我正在尝试使用WindowsAzure移动服务作为数据库进行登录注册页面。我有一个问题,当我注册为用户时,我可以用两个相同的用户名注册。是否可以使用户名唯一,这样我就不会有重复的用户名。我还想知道如何检索WAMS中的数据,以便能够检查用户名和密码以使登录部分正常工作。FYI btn1用于登录,btn2用于注册。一定要帮我做什么。谢谢

LoginRegister.java

package mp.memberuse;

import java.net.MalformedURLException;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

import com.microsoft.windowsazure.mobileservices.MobileServiceClient;
import com.microsoft.windowsazure.mobileservices.MobileServiceTable;
import com.microsoft.windowsazure.mobileservices.ServiceFilterResponse;
import com.microsoft.windowsazure.mobileservices.TableOperationCallback;

public class LoginRegister extends Activity {

Button btn1, btn2, btn3;
EditText tf1, tf2, tf3, tf4, tf5, tf6, tf7, tf8, tf9, tf10, tf11;
TextView tv1, tv2;

private MobileServiceClient mClient;
private MobileServiceTable<Members> mMembersTable;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    TabHost tabs = (TabHost) this.findViewById(R.id.lt2tabhost);
    tabs.setup();

    TabSpec ts1 = tabs.newTabSpec("Login");
    ts1.setIndicator("Login");
    ts1.setContent(R.id.c1);
    tabs.addTab(ts1);

    TabSpec ts2 = tabs.newTabSpec("Register");
    ts2.setIndicator("Register");
    ts2.setContent(R.id.c2);
    tabs.addTab(ts2);

    btn1 = (Button)findViewById(R.id.button1);
    btn2 = (Button)findViewById(R.id.button2);
    btn3 = (Button)findViewById(R.id.button3);

    tf1=(EditText) findViewById(R.id.editText1);
    tf2=(EditText) findViewById(R.id.editText2);
    tf3=(EditText) findViewById(R.id.editText3);
    tf4=(EditText) findViewById(R.id.editText4);
    tf5=(EditText) findViewById(R.id.editText5);
    tf6=(EditText) findViewById(R.id.editText6);
    tf7=(EditText) findViewById(R.id.editText7);
    tf8=(EditText) findViewById(R.id.editText8);
    tf9=(EditText) findViewById(R.id.editText9);
    tf10=(EditText) findViewById(R.id.editText10);

    tv1=(TextView) findViewById(R.id.login);
    tv2=(TextView) findViewById(R.id.register);

    try {
        // Create the Mobile Service Client instance, using the provided
        // Mobile Service URL and key
        mClient = new MobileServiceClient(
                  "**************",
                  "**************",
                  this
            );

        // Get the Mobile Service Table instance to use
        mMembersTable = mClient.getTable(Members.class);


        } catch (MalformedURLException e) {
            //createAndShowDialog(new Exception("There was an error creating the Mobile Service. Verify the URL"), "Error");
        }

    btn1.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v)
        {
            String username, password;
            username = tf1.getText().toString();
            password = tf2.getText().toString();
        }
    });

    btn2.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v)
        {
            String username, password, cpassword, fullname, nric, address, phone, email;
            username = tf3.getText().toString();
            password = tf4.getText().toString();
            cpassword = tf5.getText().toString();
            fullname = tf6.getText().toString();
            nric = tf7.getText().toString();
            address = tf8.getText().toString();
            phone = tf9.getText().toString();
            email = tf10.getText().toString();

            if (mClient == null) {
                return;
            }

            Members mbs = new Members();

            mbs.setUsername(username);
            mbs.setPassword(password);
            mbs.setFullname(fullname);
            mbs.setNric(nric);
            mbs.setAddress(address);
            mbs.setPhone(phone);
            mbs.setEmail(email);

            if(!password.equals(cpassword))
            {
                tv2.setText("Password & Confirm Password does not match.");
            }
            else if(username.equals("") || password.equals("") || cpassword.equals("") || fullname.equals("") || nric.equals("") || address.equals("") || phone.equals("") || email.equals(""))
            {
                tv2.setText("Do not leave any field empty.");
            }
            else
            {
                mMembersTable.insert(mbs, new TableOperationCallback<Members>() 
                {

                            public void onCompleted(Members entity, Exception exception, ServiceFilterResponse response) 
                            {

                                if (exception == null) 
                                {
                                    tv2.setText("Register Complete.");
                                    tf3.setText("");
                                    tf4.setText("");
                                    tf5.setText("");
                                    tf6.setText("");
                                    tf7.setText("");
                                    tf8.setText("");
                                    tf9.setText("");
                                    tf10.setText(""); 
                                } 
                                else 
                                {
                                    tv2.setText("Fail to register!");
                                    tf3.setText("");
                                    tf4.setText("");
                                    tf5.setText("");
                                    tf6.setText("");
                                    tf7.setText("");
                                    tf8.setText("");
                                    tf9.setText("");
                                    tf10.setText("");
                                }

                            }
                });         
            }
        }
    });

    btn3.setOnClickListener(new View.OnClickListener(){
        public void onClick(View v)
        {
            tf3.setText("");
            tf4.setText("");
            tf5.setText("");
            tf6.setText("");
            tf7.setText("");
            tf8.setText("");
            tf9.setText("");
            tf10.setText("");           
        }
    });
}
}

在表中插入新值时,应使用服务器脚本检查表中是否已存在该名称。例如,检查。另外,请不要将普通密码存储在表中,而是使用相同的插入脚本对密码进行散列并存储散列

Josh Twist展示了如何使用移动服务构建自定义身份

谢谢,亚弗

package mp.memberuse;

public class Members {

@com.google.gson.annotations.SerializedName("id")
private int mId;

@com.google.gson.annotations.SerializedName("username")
private String mUsername;

@com.google.gson.annotations.SerializedName("password")
private String mPassword;

@com.google.gson.annotations.SerializedName("fullname")
private String mFullname;

@com.google.gson.annotations.SerializedName("nric")
private String mNric;

@com.google.gson.annotations.SerializedName("address")
private String mAddress;

@com.google.gson.annotations.SerializedName("phone")
private String mPhone;

@com.google.gson.annotations.SerializedName("email")
private String mEmail;

public Members() {

}

public Members(int id, String username, String password, String fullname, String nric, String address, String phone, String email) {
    this.setId(id);
    this.setUsername(username);
    this.setPassword(password);
    this.setFullname(fullname);
    this.setNric(nric);
    this.setAddress(address);
    this.setPhone(phone);
    this.setEmail(email);
}

public int getId() {
    return mId;
}

public final void setId(int id) {
    mId = id;
}

public String getUsername() {
    return mUsername;
}

public final void setUsername(String username) {
    mUsername = username;
}

public String getPassword() {
    return mPassword;
}

public final void setPassword(String password) {
    mPassword = password;
}

public String getFullname() {
    return mFullname;
}

public final void setFullname(String fullname) {
    mFullname = fullname;
}

public String getNric() {
    return mNric;
}

public final void setNric(String nric) {
    mNric = nric;
}

public String getAddress() {
    return mAddress;
}

public final void setAddress(String address) {
    mAddress = address;
}

public String getPhone() {
    return mPhone;
}

public final void setPhone(String phone) {
    mPhone = phone;
}

public String getEmail() {
    return mEmail;
}

public final void setEmail(String email) {
    mEmail = email;
}
}