---
title: 'ClientRegist'
disqus: hackmd
tags: 'so'
---
## **Register from Client**
How to produce a function that allows registration from Client.
Click to register.

Enter account/password/mailbox and click Regist to register.

```
C#
using UnityEngine;
using System.Collections;
public class Sample_Regist : MonoBehaviour {
/*******************************************************************
* Copyright © 2022 SPKITA Game Cloud. All Rights Reserved
*
*******************************************************************/
//Enter the gguid shown in the developer backstage here
private const string gguid = "";
//Enter the verification shown in the developer backstage here
byte[] certificate = {};
//Declare CloudGame and this Class will be in charge of the communication with Cloud Server
public CloudGame ag = null;
string userAcc; //User’s account
string userPwd; //User’s password
void Start()
{
CloudSystem.UnityEnvironment();
CloudSystem.ServerProvider("sgc-api-us.spkita.com"); // set the server
}
void OnApplicationQuit()
{
//When the program is closed, the user’s account will not be logged out. Here we can add a mechanism that allows automatic logging out.
if(ag!=null) ag.Dispose();
}
public void LoginBtnClick()
{
userAcc = login_input_acc.text;
userPwd = login_input_pwd.text;
//the parameters needed when logging in, which are (account, password, gguid, certificate)
ag = new CloudGame(userAcc, userPwd, gguid, certificate);
//Designate the way of management and start the detection on whether the connection is successful
ag.onCompletion += CloudLaunch;
ag.UnityLaunch();
}
/*******************************************************************
// After CloudGame finishes its execution, in CallBack there will be a message about whether the login is successful.
// When the code is 0, the login succeeds and when the code is not 0, the login fails
// refer the errors in login to Error Code
//
*******************************************************************/
void CloudLaunch(int code, CloudGame game)
{
if (code == 0)
{
Debug.Log("Login Success! My poid : " + ag.poid + " NickName : " + ag.nickname);
}
else
{
Debug.LogWarning("Login Fail! Code : " + code);
}
}
/*******************************************************************
* the registration function must include account/password/E-Mail
*******************************************************************/
public void RegistBtnClick()
{
string acc = regist_input_acc.text;
string pwd = regist_input_pwd.text;
string mail = regist_input_mail.text;
string[] registToken = new string[] { acc, pwd, mail };
CloudSystem.ApplyNewUser(gguid, certificate, acc, pwd, mail, CB_regist, registToken);
}
/*******************************************************************
* for the CallBack one registers, when the code is 0, the login succeeds and when the code is not 0, the login fails
*******************************************************************/
void CB_regist(int code, object token)
{
if (code == 0)
{
string[] reg = token as string[]; //Get Token
string acc = reg[0];
string pwd = reg[1];
string mail = reg[2];
login_input_acc.text = acc;
login_input_pwd.text = pwd;
GoBackLoginBtn();
Debug.Log("Regist Success! - Account: " + acc + " / Password: " + pwd + " / E-Mail: " + mail);
}
else
{
Debug.LogWarning("Regist Fail! Code: " + code);
}
}
}
```