LoginSignup
1
1

More than 5 years have passed since last update.

ニフティクラウド mobile backendのUnity SDKを使い倒してみる-NCMBUser編-

Posted at

.Add .SignUpAsync

とりあえず登録

NCMB-test.cs
using UnityEngine;
using System.Collections;
using NCMB;
using System.Collections.Generic;


public class NCMB_test : MonoBehaviour {

    // Use this for initialization
    void Start () {
        // 新規登録
        NCMBUser user = new NCMBUser();
        user.UserName = "user1";
        user.Password = "password1";
        user.Email = "email@example.com";

        // 任意フィールドに値を追加 
        user.Add("phone", "987-654-3210");
        user.SignUpAsync ((NCMBException e) => { 
            if (e != null) {
                UnityEngine.Debug.Log ("新規登録に失敗: " + e.ErrorMessage);
            } else {
                UnityEngine.Debug.Log ("新規登録に成功");
            }
        });
    }

    // Update is called once per frame
    void Update () {

    }
}

結果こんな風になる

スクリーンショット 2015-10-12 0.30.00.png

以下から
void Start ()
の中の部分だけ記述する

.RequestAuthenticationMailAsync

メールによる会員登録を行うメソッド

NCMB-test.cs
NCMBUser.RequestAuthenticationMailAsync ("email@example.com", (NCMBException e) => {
            if (e != null) {
                UnityEngine.Debug.Log ("新規登録に失敗: " + e.ErrorMessage);
            } else {
                UnityEngine.Debug.Log ("新規登録に成功");
            }
        });

するとメールアドレスにメールがとどき、そこから下記のフォームへと飛べる
スクリーンショット 2015-10-12 10.11.49.png

登録を行うとDBも更新される
スクリーンショット 2015-10-12 10.38.00.png

.LoginAsync .LogInWithMailAddressAsync

NCMB-test.cs
NCMBUser.LogInAsync ("user1", "password1", (NCMBException e) => {    
    if (e != null) {
        UnityEngine.Debug.Log ("ログインに失敗: " + e.ErrorMessage);
    } else {
        UnityEngine.Debug.Log ("ログインに成功!");
    }
});

NCMB-test.cs
NCMBUser.LogInWithMailAddressAsync ("email@example.com", "password", (NCMBException e) => {
    if (e != null) {
        UnityEngine.Debug.Log ("ログインに失敗: " + e.ErrorMessage);
    } else {
        UnityEngine.Debug.Log ("ログインに成功!");
    }
});

ログインは
ID・PASSのユーザーは.LogInAsyncでしかログインできなかった(メールアドレスがあっても)
mail・PASSのユーザーは.LogInWithMailAddressAsyncでしかログインできなかった(自動発行されたIDを使っても)

.CurrentUser

今ログイン中のユーザーを取得するもの

NCMB-test.cs
NCMBUser.LogInAsync ("user1", "password1", (NCMBException e) => {    
            if (e != null) {
                UnityEngine.Debug.Log ("ログインに失敗: " + e.ErrorMessage);
            } else {
                UnityEngine.Debug.Log ("ログインに成功!");
            }
        });

        System.Threading.Thread.Sleep (5000);

        NCMBUser currentUser = NCMBUser.CurrentUser;
        if (currentUser != null) {
            // ログイン中のユーザーの取得に成功
            UnityEngine.Debug.Log ("ログイン中のユーザー: " + currentUser.UserName);
        } else {
            // 未ログインまたは取得に失敗
            UnityEngine.Debug.Log ("未ログインまたは取得に失敗");
        }

.RequestPasswordResetAsync

パスワードの再発行処理

NCMB-test.cs
NCMBUser.RequestPasswordResetAsync ("email@example.com", (NCMBException e) => {    
            if (e != null) {
                UnityEngine.Debug.Log ("パスワードリセット要求に失敗: " + e.ErrorMessage);
            } else {
                UnityEngine.Debug.Log ("パスワードリセット要求に成功");
            }
        });

これを使うと勝手に、メールアドレスにメールが飛んでくる
そこに、仮パスワードと再発行処理のサイトがあるのでそちらを見ると・・・以下の画面が出る

スクリーンショット 2015-10-12 13.34.43.png

必要項目を入力したら再発行ができる

NCMBUSERはこんなところで・・・

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1