Ejemplo n.º 1
0
        public async Task GetRegistrationFirebase(string License)
        {
            if (IsFirebaseConnected())
            {
                FirebaseResponse fbResponse = await fbClient.GetTaskAsync(Globals.FIREBASE_PATH_LICENSE + License);

                _user = null;

                try
                {
                    _user = fbResponse.ResultAs <_User>();
                }
                catch
                { }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Activates the license, insert the user information into the local database and creates a license file.
        /// </summary>
        /// <param name="License">License key of the user</param>
        /// <param name="ProcessorID">Processor ID of the device. Used to prevent the illegal distribution of the system.</param>
        /// <param name="_user">Hold the informatino of the user</param>
        /// <returns></returns>
        public async Task Activate(string License, string ProcessorID, _User _user)
        {
            try
            {
                _user.ISACTIVATED = 1;
                await fbClient.SetTaskAsync("License/" + License, _user);

                //create license file (License.txt)
                using (StreamWriter file = new StreamWriter(Globals.LicenseFile))
                {
                    //insert hashing
                    file.WriteLine(License);
                }

                using (SQLiteConnection con = new SQLiteConnection(Globals.DbConString))
                {
                    string query = "INSERT OR REPLACE INTO tblUsers VALUES(@license, @username, @password, @name, @email, @isactivated, @processorid);";
                    using (SQLiteCommand cmd = new SQLiteCommand(query, con))
                    {
                        cmd.Parameters.Add("@license", DbType.String).Value     = License;
                        cmd.Parameters.Add("@username", DbType.String).Value    = _user.USERNAME;
                        cmd.Parameters.Add("@password", DbType.String).Value    = _user.PASSWORD;
                        cmd.Parameters.Add("@name", DbType.String).Value        = _user.NAME;
                        cmd.Parameters.Add("@email", DbType.String).Value       = _user.EMAIL;
                        cmd.Parameters.Add("@isactivated", DbType.Int32).Value  = 1;
                        cmd.Parameters.Add("@processorid", DbType.String).Value = ProcessorID;

                        con.Open();
                        cmd.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }
Ejemplo n.º 3
0
        public async Task DeactivateFirebase(string License)
        {
            try
            {
                _User _user = new _User();

                using (SQLiteConnection con = new SQLiteConnection(Globals.DbConString))
                {
                    string query = "SELECT NAME, EMAIL, USERNAME, PASSWORD FROM tblUsers WHERE LICENSE = @license;";
                    using (SQLiteCommand cmd = new SQLiteCommand(query, con))
                    {
                        cmd.Parameters.Add("@license", DbType.String).Value = License;

                        con.Open();

                        using (SQLiteDataReader reader = cmd.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                _user.NAME        = reader[0].ToString();
                                _user.EMAIL       = reader[1].ToString();
                                _user.USERNAME    = reader[2].ToString();
                                _user.PASSWORD    = reader[3].ToString();
                                _user.ISACTIVATED = 0;

                                await fbClient.SetTaskAsync(Globals.FIREBASE_PATH_LICENSE + License, _user);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
        }