Beispiel #1
0
        /// <summary>
        /// Sends a generic login request
        /// </summary>
        public void SignIn(MstProperties data, SignInCallback callback, IClientSocket connection)
        {
            Logs.Debug("Signing in...");

            if (!connection.IsConnected)
            {
                callback.Invoke(null, "Not connected to server");
                return;
            }

            IsNowSigningIn = true;

            // We first need to get an aes key
            // so that we can encrypt our login data
            Mst.Security.GetAesKey(aesKey =>
            {
                if (aesKey == null)
                {
                    IsNowSigningIn = false;
                    callback.Invoke(null, "Failed to log in due to security issues");
                    return;
                }

                var encryptedData = Mst.Security.EncryptAES(data.ToBytes(), aesKey);

                connection.SendMessage((short)MstMessageCodes.SignInRequest, encryptedData, (status, response) =>
                {
                    IsNowSigningIn = false;

                    if (status != ResponseStatus.Success)
                    {
                        ClearAuthToken();

                        callback.Invoke(null, response.AsString("Unknown error"));
                        return;
                    }

                    AccountInfo = response.Deserialize(new AccountInfoPacket());

                    IsSignedIn = true;

                    if (RememberMe)
                    {
                        SaveAuthToken(AccountInfo.Token);
                    }
                    else
                    {
                        ClearAuthToken();
                    }

                    callback.Invoke(AccountInfo, null);

                    OnSignedInEvent?.Invoke();
                });
            }, connection);
        }
Beispiel #2
0
        /// <summary>
        /// Sends a generic login request
        /// </summary>
        public void SignIn(MstProperties data, SignInCallback callback, IClientSocket connection)
        {
            Logs.Debug("Signing in...");

            if (!connection.IsConnected)
            {
                callback.Invoke(null, "Not connected to server");
                return;
            }

            IsNowSigningIn = true;

            // We first need to get an aes key
            // so that we can encrypt our login data
            Mst.Security.GetAesKey(aesKey =>
            {
                if (aesKey == null)
                {
                    IsNowSigningIn = false;
                    callback.Invoke(null, "Failed to log in due to security issues");
                    return;
                }

                var encryptedData = Mst.Security.EncryptAES(data.ToBytes(), aesKey);

                connection.SendMessage((short)MstMessageCodes.SignIn, encryptedData, (status, response) =>
                {
                    IsNowSigningIn = false;

                    if (status != ResponseStatus.Success)
                    {
                        ClearAuthToken();

                        callback.Invoke(null, response.AsString("Unknown error"));
                        return;
                    }

                    // Parse account info
                    var accountInfoPacket = response.Deserialize(new AccountInfoPacket());

                    AccountInfo = new ClientAccountInfo()
                    {
                        Id               = accountInfoPacket.Id,
                        Username         = accountInfoPacket.Username,
                        Email            = accountInfoPacket.Email,
                        PhoneNumber      = accountInfoPacket.PhoneNumber,
                        Facebook         = accountInfoPacket.Facebook,
                        Token            = accountInfoPacket.Token,
                        IsAdmin          = accountInfoPacket.IsAdmin,
                        IsGuest          = accountInfoPacket.IsGuest,
                        IsEmailConfirmed = accountInfoPacket.IsEmailConfirmed,
                        Properties       = accountInfoPacket.Properties,
                    };

                    // If RememberMe is checked on and we are not guset, then save auth token
                    if (RememberMe && !AccountInfo.IsGuest && !string.IsNullOrEmpty(AccountInfo.Token))
                    {
                        SaveAuthToken(AccountInfo.Token);
                    }
                    else
                    {
                        ClearAuthToken();
                    }

                    IsSignedIn = true;

                    callback.Invoke(AccountInfo, null);

                    OnSignedInEvent?.Invoke();
                });
            }, connection);
        }