예제 #1
0
 /// <summary>
 /// Verifies that the user is an admin
 /// </summary>
 protected void CheckAdmin()
 {
     if (!Global_Functions.CheckAdminLogin())
     {
         Response.Redirect("~/Home.aspx");
     }
 }
예제 #2
0
    /// <summary>
    /// Verifies Login Information
    /// </summary>
    /// <param name="UserName"></param>
    /// <param name="Password"></param>
    /// <returns></returns>
    public static bool CheckLogin(string UserName, string Password)
    {
        using (SqlConnection conn = ConnectionFactory.DistributeConnection("DB"))
        {
            conn.Open();
            string     sql = "SELECT salt,password FROM WEBSITE_ADMIN WHERE username=@Username";
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.Parameters.Add(new SqlParameter("@Username", UserName));
            SqlDataReader dr = cmd.ExecuteReader();

            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    if (Global_Functions.GetHashString(Password, dr["salt"].ToString()) == dr["password"].ToString())
                    {
                        UpdateLastLogin(UserName);
                        dr.Close();
                        conn.Close();
                        conn.Dispose();
                        return(true);
                    }
                }
                dr.Close();
            }
        }
        return(false);
    }
예제 #3
0
 void Start()
 {
     point = new List <Vector3>();
     //Synthesis.Init(o, c, point);
     for (int i = 0; i < o.Count; i++)
     {
         point.Add(Global_Functions.get_new_point(o[i], c[0].transform.position));
     }
     point[1] = new Vector3(point[1].x + 4 * Global_Functions.get_radius(c[0]), point[1].y, point[1].z);
 }
예제 #4
0
 void OnGUI()
 {
     Synthesis.Interface(o, c, point, ref start, ref speed, "O2+C=CO2", style);
     if (start)
     {
         StartCoroutine(Change_texts());
     }
     if (start)
     {
         for (int i = 0; i < o.Count; i++)
         {
             Global_Functions.Start_Anim(start, o[i], point[i], speed);
         }
     }
 }
예제 #5
0
    /// <summary>
    /// Used to Create a New Admin Account
    /// </summary>
    /// <param name="UserName"></param>
    /// <param name="Password"></param>
    public static void InsertAdmin(string UserName, string Password)
    {
        string salt     = Global_Functions.SaltGenerator();
        string hashPass = Global_Functions.GetHashString(Password, salt);

        using (SqlConnection conn = ConnectionFactory.DistributeConnection("DB"))
        {
            conn.Open();
            string     sql = "INSERT INTO WEBSITE_ADMIN (username, password,last_login,active,salt) VALUES (@Username, @Password, @LastLogin, @Active, @Salt)";
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.Parameters.Add(new SqlParameter("@Username", UserName));
            cmd.Parameters.Add(new SqlParameter("@Password", hashPass));
            cmd.Parameters.Add(new SqlParameter("@Salt", salt));
            cmd.Parameters.Add(new SqlParameter("@LastLogin", DateTime.Now));
            cmd.Parameters.Add(new SqlParameter("@Active", 1));
            cmd.ExecuteNonQuery();
        }
    }
예제 #6
0
    /// <summary>
    /// Login Button Event
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Submitbtn_Click(object sender, EventArgs e)
    {
        if (SQL_Functions.CheckLogin(UserNametxt.Text, Passwordtxt.Text) == true)
        {
            UserNametxt.Attributes.Add("class", "");
            Passwordtxt.Attributes.Add("class", "");
            Errorlb.Visible = false;

            Global_Functions.SetSessionUp(UserNametxt.Text);
            CheckAuth();
        }
        else
        {
            UserNametxt.Attributes.Add("class", "error");
            Passwordtxt.Attributes.Add("class", "error");
            Errorlb.Visible = true;
        }
    }
예제 #7
0
    static public void Interface(List <GameObject> X, List <GameObject> Y, List <Vector3> point, ref bool state, ref float speed, string formula, GUISkin style)
    {
        GUILayout.BeginArea(new Rect(0, Screen.height - 50, Screen.width, 100));
        GUILayout.BeginHorizontal();
        GUI.skin = style;
        if (state && X.Count == Y.Count)
        {
            for (int i = 0; i < X.Count; i++)
            {
                Global_Functions.Start_Anim(state, X[i], Y[i], point[i], speed);
            }
        }
        if (GUILayout.Button("Start", GUILayout.Height(50)))
        {
            state = true;
        }
        if (GUILayout.Button("Pause", GUILayout.Height(50)))
        {
            state = false;
        }
        if (GUILayout.Button("Stop", GUILayout.Height(50)))
        {
            Application.LoadLevel(Application.loadedLevel);
        }
        speed = GUILayout.HorizontalSlider(speed, 0.01f, 3.0f);
        GUILayout.Label("Current speed " + String.Format("{0:F2}", speed));

        GUILayout.EndHorizontal();
        GUILayout.EndArea();

        #region top_panel
        GUILayout.BeginArea(new Rect(0, 0, Screen.width, 100));
        GUILayout.BeginHorizontal();

        if (GUILayout.Button(formula, GUILayout.Height(100), GUILayout.Width(Screen.width)))
        {
        }
        GUILayout.EndHorizontal();
        GUILayout.EndArea();
        #endregion
    }
예제 #8
0
    public static bool AuthenticateUser(string UserName, string Password)
    {
        bool Valid = false;

        using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["DB"].ToString()))
        {
            conn.Open();
            String     sql = "select Password, UserID, FName, LName FROM FORUM_USER where UserName=@UserName";
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.Parameters.Add(new SqlParameter("@UserName", UserName));
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.HasRows)
            {
                while (dr.Read())
                {
                    if (Password == Encryption.Decrypt(dr["Password"].ToString(), Encryption.GetPassPhrase().ToString()))
                    {
                        Valid = true;
                    }
                    else
                    {
                        Valid = false;
                    }
                }
            }
            else
            {
                Valid = false;
            }

            dr.Close();
            Global_Functions globl = new Global_Functions();
            globl.CloseDB(conn);
        }
        return(Valid);
    }
예제 #9
0
 void FixedUpdate()
 {
     move_body = main_gui.move_body;
     speed     = main_gui.speed;
     if (move_body)
     {
         GetComponent <Rigidbody>().MovePosition(GetComponent <Rigidbody>().position + speed * o.transform.position * Time.deltaTime - 0.02f * new Vector3(0, Global_Functions.get_radius(gameObject), 0));
     }
     if (Input.GetKeyDown(KeyCode.S) && !move_body)
     {
         move_body = true;
     }
     if (Vector3.Distance(o.transform.position, transform.position) <= 0.9f)
     {
         if (!connect_object)
         {
             StartCoroutine(add(o));
             connect_object = true;
         }
     }
 }
예제 #10
0
 /// <summary>
 /// Logoff Button Event
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 protected void Logoffbtn_Click(object sender, EventArgs e)
 {
     Global_Functions.DisposeSession();
     CheckAuth();
 }
예제 #11
0
    /// <summary>
    /// Fills in a Code Example if an ID is avaliable
    /// </summary>
    /// <param name="CodeExampleID"></param>
    protected void WriteCodeExample(int CodeExampleID)
    {
        DataTable dt = SQL_Functions.GetCodeExample(CodeExampleID);

        if (dt.Rows.Count > 0)
        {
            foreach (DataRow row in dt.Rows)
            {
                HtmlGenericControl Container = new HtmlGenericControl("div");
                Container.Attributes.Add("class", "code-container");
                //Add A CSS Class

                //Adds Header to Container
                HtmlGenericControl Header = new HtmlGenericControl("span");
                Header.Attributes.Add("class", "code-header");
                Header.InnerText = row["project_name"].ToString();
                Container.Controls.Add(Header);


                //Horizontal Line
                Container.Controls.Add(new LiteralControl("<hr/>"));

                HtmlGenericControl p = new HtmlGenericControl("p");
                p.InnerText = row["project_description"].ToString();

                Container.Controls.Add(p);

                //Gets A code Snippet Example Block
                foreach (DataRow ExampleRow in SQL_Functions.GetCodeSamples((int)row["ID"]).Rows)
                {
                    HtmlGenericControl ExampleHeader = new HtmlGenericControl("span");
                    ExampleHeader.InnerText = (string)ExampleRow["example_title"];
                    ExampleHeader.Attributes.Add("class", "example-header");
                    Container.Controls.Add(new LiteralControl("<br/><br/>"));
                    Container.Controls.Add(ExampleHeader);
                    Container.Controls.Add(new LiteralControl("<br/>"));
                    HtmlGenericControl ExampleDescr = new HtmlGenericControl("p");
                    ExampleDescr.InnerText = (string)ExampleRow["example_description"];
                    Container.Controls.Add(ExampleDescr);

                    HtmlGenericControl preCon = new HtmlGenericControl("pre");
                    preCon.Attributes.Add("class", "pre-scrollable");

                    HtmlGenericControl codeCont = new HtmlGenericControl("code");
                    codeCont.Attributes.Add("class", row["language_text"].ToString());
                    codeCont.InnerText = (string)ExampleRow["example_body"];

                    preCon.Controls.Add(codeCont);
                    Container.Controls.Add(preCon);
                    Container.Controls.Add(new LiteralControl("<br/><br/>"));
                }

                Container.Controls.Add(new LiteralControl("<hr/> "));

                //Adds in download links
                foreach (DataRow FileRow in SQL_Functions.GetCodeFiles((int)row["ID"]).Rows)
                {
                    HtmlGenericControl FileHeader = new HtmlGenericControl("span");
                    FileHeader.InnerText = "Download the Source Files Here:";
                    Container.Controls.Add(FileHeader);
                    Container.Controls.Add(new LiteralControl("<br/><br/>"));
                    HtmlGenericControl a = new HtmlGenericControl("a");
                    a.Attributes.Add("href", FileRow["web_location"].ToString());
                    a.InnerText = FileRow["file_name"].ToString();
                    Container.Controls.Add(a);
                }

                contentpnl.Controls.Add(Container);

                Global_Functions.SetLanguageSession((int)row["language_id"], (string)row["language_text"]);
            }
        }
        else
        {
            WriteErrorPage();
        }
    }
예제 #12
0
        /// <summary>
        /// Crea el usuario si se logea si este no existe en la bd y e inicio sesion desde un proveedor externo
        /// </summary>
        /// <param name="model"></param>
        /// <param name="loginInfo"></param>
        /// <returns></returns>
        protected async Task <bool> externalLoginCreateUser_Provider(LoginExternalConfirmViewModel model, ExternalLoginInfo loginInfo)
        {
            //Aqui crear la contraseña
            Users          newpass  = new Users();
            PasswordHasher passhash = new PasswordHasher();

            string          pass  = newpass.CreateRandomPassword(7);
            string          pass2 = passhash.HashPassword(pass);
            ApplicationUser user  = new ApplicationUser
            {
                UserName       = model.usuEmail,
                Email          = model.usuEmail,
                EmailConfirmed = true,
                PasswordHash   = pass2
            };

            var userChecked = db.AspNetUsers.Where(s => s.Email == model.usuEmail).FirstOrDefault();

            if (userChecked == null)
            {
                var result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    Users  users  = new Users();
                    string idUser = users.IdUser(model.usuEmail);
                    System.Web.HttpContext.Current.Session["SessionUser"] = idUser;

                    users.EnvioCorreo(model.usuEmail, pass);
                    users.UpdateRoleUser(model.usuEmail);
                    var  promo         = users.CreateRandomPromoCode();
                    bool validatepromo = users.SavePromoCode(promo, user.Email);
                    if (validatepromo == true)
                    {
                    }
                    else
                    {
                        while (validatepromo == false)
                        {
                            promo         = users.CreateRandomPromoCode();
                            validatepromo = users.SavePromoCode(promo, model.usuEmail);
                        }
                    }
                    result = await UserManager.AddLoginAsync(user.Id, loginInfo.Login);

                    if (result.Succeeded)
                    {
                        return(true);
                    }
                    else
                    {
                        Global_Functions.saveErrors(result.Errors.ToString(), false);
                        AddErrors(result);
                    }
                }
                else
                {
                    Global_Functions.saveErrors(result.Errors.ToString(), false);
                    AddErrors(result);
                }
            }
            else
            {
                user.Id = userChecked.Id;
                //Inserta en la base de datos para que ese usuario pueda ingresar por ese proveedor con la misma cuenta de correo.
                var result = await UserManager.AddLoginAsync(user.Id, loginInfo.Login);

                if (result.Succeeded)
                {
                    return(true);
                }
                else
                {
                    Global_Functions.saveErrors(result.Errors.ToString(), false);
                    AddErrors(result);
                }
            }

            return(false);
        }