예제 #1
0
 public async void SignInToCognito(string _username, string _password)
 {
     //Console.WriteLine("SignUpToCognito Return :"+_signUpReturn);
     if (SecurityCheck.CheckUserPattern(_username))
     {
         if (SecurityCheck.CheckPasswordPattern(_password))
         {
             // This will SET a UserCognito with Valid Tokens on my Client.
             // And send the tokens to the Client who has Sign In
             //Server.clients[_fromClient].player.
             myUser = new CognitoUser(_username, Constants.CLIENTAPP_ID, Server.cognitoManagerServer.userPool, Server.cognitoManagerServer.provider, Constants.NeokySecret);
             await SignInClients.SignInClientToCognito(_username, _password, id);
         }
         else
         {
             ServerSend.AuthenticationStatus(id, Constants.AUTHENTIFICATION_FORMAT_PASSWORD_KO);
         }
     }
     else
     {
         ServerSend.AuthenticationStatus(id, Constants.AUTHENTIFICATION_FORMAT_USERNAME_KO);
     }
 }
예제 #2
0
        public async void SignUptoCognito(int _clientid, string _username, string _password, string _email)
        {
            // If the REgEx Formats are Respected, we proceed to Adhesion OR We Return an Error Format
            if (SecurityCheck.CheckUserPattern(_username))
            {
                if (SecurityCheck.CheckPasswordPattern(_password))
                {
                    if (SecurityCheck.CheckEmailPattern(_email))
                    {
                        SignUpRequest signUpRequest = new SignUpRequest()
                        {
                            ClientId   = Constants.CLIENTAPP_ID,
                            Username   = _username,
                            Password   = _password,
                            SecretHash = CognitoHashCalculator.GetSecretHash(_username, Constants.CLIENTAPP_ID, Constants.NeokySecret)
                        };

                        List <AttributeType> attributes = new List <AttributeType>()
                        {
                            new AttributeType()
                            {
                                Name = "email", Value = _email
                            }
                        };

                        // Send SignupRequest
                        signUpRequest.UserAttributes = attributes;

                        try
                        {
                            SignUpResponse result = await Server.cognitoManagerServer.provider.SignUpAsync(signUpRequest);

                            if (result.HttpStatusCode == System.Net.HttpStatusCode.OK)
                            {
                                ServerSend.SignUpStatusReturn(_clientid, Constants.ADHESION_OK);
                            }
                        }
                        catch (Exception e)
                        {
                            switch (e.GetType().ToString())
                            {
                            case "Amazon.CognitoIdentityProvider.Model.UsernameExistsException":
                                ServerSend.SignUpStatusReturn(_clientid, Constants.ADHESION_ALREADY_EXIST);
                                break;

                            default:
                                NlogClass.target.WriteAsyncLogEvent(new AsyncLogEventInfo(new LogEventInfo(LogLevel.Error, "SignUpClientToCognito", "Client ID : " + _clientid.ToString() + "  | New Exception | Code : " + e.GetType().ToString() + " | Exeption : " + e.Message), NlogClass.exceptions.Add));
                                ServerSend.SignUpStatusReturn(_clientid, Constants.ADHESION_KO);
                                break;
                            }
                        }
                    }
                    else
                    {
                        ServerSend.SignUpStatusReturn(_clientid, Constants.ADHESION_FORMAT_EMAIL_KO);
                    }
                }
                else
                {
                    ServerSend.SignUpStatusReturn(_clientid, Constants.ADHESION_FORMAT_PASSWORD_KO);
                }
            }
            else
            {
                ServerSend.SignUpStatusReturn(_clientid, Constants.ADHESION_FORMAT_USERNAME_KO);
            }
        }