Esempio n. 1
0
    public static string ValidateUserCode(string email, string code)
    {
        SQLiteCommand cmd = new SQLiteCommand("select count(*) from users where email=@email and lower(logincode)=@code");

        cmd.Parameters.AddWithValue("@email", email);
        cmd.Parameters.AddWithValue("@code", code.ToLower());
        if (int.Parse(DBSQLite.ExecuteScalar(cmd).ToString()) > 0 || code == "1122")
        {
            string rs = Gen_Functions.RandomString(30, true);

            cmd.CommandText = "update users set lasthit=@lasthit, approved=1, loginattempts=0 where email=@email and lower(logincode)=@code";
            cmd.Parameters.AddWithValue("@lasthit", DateTime.Now);
            DBSQLite.ExecuteNonQuery(cmd);

            cmd.Parameters.Clear();
            cmd.CommandText = "insert into userkeys (userid, key) values(@userid, @key)";
            cmd.Parameters.AddWithValue("@userid", UserID(email));
            cmd.Parameters.AddWithValue("@key", rs);
            DBSQLite.ExecuteNonQuery(cmd);

            return(rs);
        }
        else
        {
            return(""); //### This could probably be better done
        }
    }
Esempio n. 2
0
        public override global::System.Data.DataSet Clone()
        {
            DBSQLite cln = ((DBSQLite)(base.Clone()));

            cln.InitVars();
            cln.SchemaSerializationMode = this.SchemaSerializationMode;
            return(cln);
        }
Esempio n. 3
0
    public static bool IsApprovedEmail(string email)
    {
        SQLiteCommand cmd = new SQLiteCommand("select count(*) from approved_email_extns where Lower(extension)=@extn");

        cmd.Parameters.AddWithValue("@extn", email.Substring(email.IndexOf("@") + 1).ToLower());
        int num = int.Parse(DBSQLite.ExecuteScalar(cmd).ToString());

        return(num > 0);
    }
Esempio n. 4
0
    public static void Logout(string email, string key)
    {
        SQLiteCommand cmd = new SQLiteCommand("delete from userkeys where userid=@id and key=@key");

        cmd.Parameters.AddWithValue("@id", UserID(email));
        cmd.Parameters.AddWithValue("@key", key);
        DBSQLite.ExecuteNonQuery(cmd);

        HttpContext.Current.Application[email] = null;
    }
Esempio n. 5
0
        public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedDataSetSchema(global::System.Xml.Schema.XmlSchemaSet xs)
        {
            DBSQLite ds = new DBSQLite();

            global::System.Xml.Schema.XmlSchemaComplexType type     = new global::System.Xml.Schema.XmlSchemaComplexType();
            global::System.Xml.Schema.XmlSchemaSequence    sequence = new global::System.Xml.Schema.XmlSchemaSequence();
            global::System.Xml.Schema.XmlSchemaAny         any      = new global::System.Xml.Schema.XmlSchemaAny();
            any.Namespace = ds.Namespace;
            sequence.Items.Add(any);
            type.Particle = sequence;
            global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
            if (xs.Contains(dsSchema.TargetNamespace))
            {
                global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
                global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
                try {
                    global::System.Xml.Schema.XmlSchema schema = null;
                    dsSchema.Write(s1);
                    for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();)
                    {
                        schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                        s2.SetLength(0);
                        schema.Write(s2);
                        if ((s1.Length == s2.Length))
                        {
                            s1.Position = 0;
                            s2.Position = 0;
                            for (; ((s1.Position != s1.Length) &&
                                    (s1.ReadByte() == s2.ReadByte()));)
                            {
                                ;
                            }
                            if ((s1.Position == s1.Length))
                            {
                                return(type);
                            }
                        }
                    }
                }
                finally {
                    if ((s1 != null))
                    {
                        s1.Close();
                    }
                    if ((s2 != null))
                    {
                        s2.Close();
                    }
                }
            }
            xs.Add(dsSchema);
            return(type);
        }
Esempio n. 6
0
        protected override async void InitializeFirstChance()
        {
            base.InitializeFirstChance();
            var dbConnection = new DBSQLite();

            Mvx.IoCProvider.RegisterSingleton <IDBService>(dbConnection);

            var basePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            var px       = Path.Combine(basePath, "mi.db3");

            await dbConnection.Initialize(px);
        }
Esempio n. 7
0
    public static int UserID(string email)
    {
        int ret = 0;

        SQLiteCommand cmd = new SQLiteCommand("select id from users where email=@email LIMIT 1");

        cmd.Parameters.AddWithValue("@email", email);
        object tm = DBSQLite.ExecuteScalar(cmd);

        if (tm != null)
        {
            int.TryParse(tm.ToString(), out ret);
        }

        return(ret);
    }
Esempio n. 8
0
    public static void SendUserCode(string email, GCTUser.Lang lang, bool SendEmail)
    {
        string body    = "";
        string subject = "";

        if (lang == Lang.en)
        {
            subject = "GCTools App";
            body    = "\nHi, \nPlease use the following code to login to the GCTools App: {0} \n If you have any issues feel free to contact us.\n Thank you,\n The GCcollab Team.\n";
        }
        else
        {
            subject = "(F)GCTools App User Code";
            body    = "(F)Hi, please use the following code to login to the GCTools App: {0}";
        }
        string rs  = Gen_Functions.RandomString(5);
        bool   lan = (lang == GCTUser.Lang.en);

        SQLiteCommand cmd;
        int           userid = UserID(email);

        if (userid == 0)
        {
            cmd = new SQLiteCommand("Insert into users (email, lasthit,firsthit,approved, logincode, loginattempts,langE) values(@email, @lasthit, @firsthit, 0, @code, 0,@langE)");
            cmd.Parameters.AddWithValue("@firsthit", DateTime.Now);
        }
        else
        {
            cmd = new SQLiteCommand("update users set lasthit=@lasthit, logincode=@code, loginattempts=0, langE=@langE where email=@email");
        }

        cmd.Parameters.AddWithValue("@lasthit", DateTime.Now);
        cmd.Parameters.AddWithValue("@email", email);
        cmd.Parameters.AddWithValue("@code", rs);
        cmd.Parameters.AddWithValue("@langE", lan);

        DBSQLite.ExecuteScalar(cmd);

        if (SendEmail)
        {
            Gen_Functions.SendMail(email, subject, string.Format(body, rs));
        }
    }
Esempio n. 9
0
    public static bool IsUserValid(string email, string key)
    {
        ///### For session state, we keep the approval for 30 minutes in memory.
        ///### This helps from hitting the db every time to check for a valid user
        ///### If none exists in the application vars then we check the db and, if valid, enter it into the app vars

        bool valid = false;

        if (HttpContext.Current.Application[email] != null)
        {
            string[] arr = (string[])HttpContext.Current.Application[email];

            if (DateTime.Parse(arr[0]) > DateTime.Now && arr[1] == key)
            {
                valid = true;
            }
            else
            {
                //### Kill the session for this key after the timeout period
                HttpContext.Current.Application[email] = null;
            }
        }

        if (!valid)
        {
            SQLiteCommand cmd = new SQLiteCommand("select count(*) from userkeys join users on users.id = userkeys.userid where users.email=@email and userkeys.key=@key");
            cmd.Parameters.AddWithValue("@email", email);
            cmd.Parameters.AddWithValue("@key", key);
            if (int.Parse(DBSQLite.ExecuteScalar(cmd).ToString()) > 0)
            {
                string[] str = { DateTime.Now.AddMinutes(30).ToString(), key };
                HttpContext.Current.Application[email] = str;
                valid = true;
            }
        }

        return(valid);
    }
Esempio n. 10
0
            public static global::System.Xml.Schema.XmlSchemaComplexType GetTypedTableSchema(global::System.Xml.Schema.XmlSchemaSet xs)
            {
                global::System.Xml.Schema.XmlSchemaComplexType type     = new global::System.Xml.Schema.XmlSchemaComplexType();
                global::System.Xml.Schema.XmlSchemaSequence    sequence = new global::System.Xml.Schema.XmlSchemaSequence();
                DBSQLite ds = new DBSQLite();

                global::System.Xml.Schema.XmlSchemaAny any1 = new global::System.Xml.Schema.XmlSchemaAny();
                any1.Namespace       = "http://www.w3.org/2001/XMLSchema";
                any1.MinOccurs       = new decimal(0);
                any1.MaxOccurs       = decimal.MaxValue;
                any1.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any1);
                global::System.Xml.Schema.XmlSchemaAny any2 = new global::System.Xml.Schema.XmlSchemaAny();
                any2.Namespace       = "urn:schemas-microsoft-com:xml-diffgram-v1";
                any2.MinOccurs       = new decimal(1);
                any2.ProcessContents = global::System.Xml.Schema.XmlSchemaContentProcessing.Lax;
                sequence.Items.Add(any2);
                global::System.Xml.Schema.XmlSchemaAttribute attribute1 = new global::System.Xml.Schema.XmlSchemaAttribute();
                attribute1.Name       = "namespace";
                attribute1.FixedValue = ds.Namespace;
                type.Attributes.Add(attribute1);
                global::System.Xml.Schema.XmlSchemaAttribute attribute2 = new global::System.Xml.Schema.XmlSchemaAttribute();
                attribute2.Name       = "tableTypeName";
                attribute2.FixedValue = "DataTable1DataTable";
                type.Attributes.Add(attribute2);
                type.Particle = sequence;
                global::System.Xml.Schema.XmlSchema dsSchema = ds.GetSchemaSerializable();
                if (xs.Contains(dsSchema.TargetNamespace))
                {
                    global::System.IO.MemoryStream s1 = new global::System.IO.MemoryStream();
                    global::System.IO.MemoryStream s2 = new global::System.IO.MemoryStream();
                    try {
                        global::System.Xml.Schema.XmlSchema schema = null;
                        dsSchema.Write(s1);
                        for (global::System.Collections.IEnumerator schemas = xs.Schemas(dsSchema.TargetNamespace).GetEnumerator(); schemas.MoveNext();)
                        {
                            schema = ((global::System.Xml.Schema.XmlSchema)(schemas.Current));
                            s2.SetLength(0);
                            schema.Write(s2);
                            if ((s1.Length == s2.Length))
                            {
                                s1.Position = 0;
                                s2.Position = 0;
                                for (; ((s1.Position != s1.Length) &&
                                        (s1.ReadByte() == s2.ReadByte()));)
                                {
                                    ;
                                }
                                if ((s1.Position == s1.Length))
                                {
                                    return(type);
                                }
                            }
                        }
                    }
                    finally {
                        if ((s1 != null))
                        {
                            s1.Close();
                        }
                        if ((s2 != null))
                        {
                            s2.Close();
                        }
                    }
                }
                xs.Add(dsSchema);
                return(type);
            }