Exemple #1
0
        public static async Task <string> Login(string email, string password)
        {
            string hashedPass = StringHash.HashedPassword(password);

            string result   = "";
            var    response = await UserAPI_Logic.GetToken(email, hashedPass);

            if (response[0].ToString() == "Token")
            {
                using (SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation))
                {
                    var userObject = response[1] as User;
                    conn.CreateTable <UserPost>();
                    try
                    {
                        string dekoduotasTokenas = StringHash.DecryptToken(userObject.userToken);
                        var    user = conn.Find <UserPost>(email);
                        if (user == null)
                        {
                            UserPost post = new UserPost()
                            {
                                Token         = dekoduotasTokenas,
                                Email         = email,
                                Password      = password,
                                Name          = userObject.name,
                                Address       = userObject.address,
                                Phone_number  = Convert.ToInt32(userObject.phone_number),
                                Postal_code   = Convert.ToInt32(userObject.postal_code),
                                Discount_code = userObject.discount_code,
                                City          = userObject.city
                            };
                            conn.InsertOrReplace(post);
                        }
                        else
                        {
                            /* if (response[1] != user.Token)
                             * {
                             *   //Padaryt tokeno update
                             * }*/
                        }
                    }
                    catch (NullReferenceException nrex)
                    {
                    }
                    conn.Close();
                }
            }
            else
            {
                result = response[1].ToString();
            }
            return(result);
        }
Exemple #2
0
        public static async Task <string> Register(string email, string password)
        {
            string hashedPass = StringHash.HashedPassword(password);

            string result   = "";
            var    response = await UserAPI_Logic.RegisterUser(email, hashedPass);

            if (response[0] == "Token")
            {
                using (SQLiteConnection conn = new SQLiteConnection(App.DatabaseLocation))
                {
                    conn.CreateTable <UserPost>();
                    try
                    {
                        string dekoduotasTokenas = StringHash.DecryptToken(response[1]);
                        var    user = conn.Find <UserPost>(email);
                        if (user == null)
                        {
                            UserPost post = new UserPost()
                            {
                                Token    = dekoduotasTokenas,
                                Email    = email,
                                Password = password
                            };
                            conn.InsertOrReplace(post);
                        }
                        else
                        {
                            /* if (response[1] != user.Token)
                             * {
                             *   //Padaryt tokeno update
                             * }*/
                        }
                    }
                    catch (NullReferenceException nrex)
                    {
                    }
                    conn.Close();
                }
            }
            else
            {
                result = response[1];
            }
            return(result);
        }