예제 #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Int32    FORMULARIO = 16;
        LIdioma  idioma     = new LIdioma();
        UIdioma  com        = new UIdioma();
        LUser    user       = new LUser();
        UUser    emp        = new UUser();
        UUsuario dato       = new UUsuario();
        LUsuario luser      = new LUsuario();


        try
        {
            int DDL = int.Parse(Session["ddl"].ToString());
            com = idioma.idiomaLoggin(FORMULARIO, DDL);
        }
        catch
        {
            int DDL = 1;
            com = idioma.idiomaLoggin(FORMULARIO, DDL);
        }

        Hashtable compIdioma = new Hashtable();

        Session["mensajes"]     = compIdioma;
        LB_Login.Text           = com.A;
        LB_username.Text        = com.B;
        validator_username.Text = com.C;
        LB_pass.Text            = com.D;
        LB_Recuperar.Text       = com.E;
        B_Login.Text            = com.F;
        B_Registrarse.Text      = com.G;
        Session["men"]          = com.H;
        Session["men1"]         = com.I;
        Session["men2"]         = com.J;
        Session["men3"]         = com.K;


        GoogleConnect.ClientId     = "326076519225-vg67uko89vu71hcetltti24jsvbenk33.apps.googleusercontent.com";
        GoogleConnect.ClientSecret = "MMHhqYJwIWXP4Bz_eAthOto9";
        GoogleConnect.RedirectUri  = Request.Url.AbsoluteUri.Split('?')[0];

        if (!string.IsNullOrEmpty(Request.QueryString["code"]))
        {
            try
            {
                string        code    = Request.QueryString["code"];
                string        json    = GoogleConnect.Fetch("me", code);
                GoogleProfile profile = new JavaScriptSerializer().Deserialize <GoogleProfile>(json);
                Session["password"]  = profile.Id;
                Session["user_name"] = profile.DisplayName;
                Session["correo"]    = profile.Emails.Find(email => email.Type == "account").Value;
                Session["band"]      = true;

                //Image1.ImageUrl = profile.Im/ImageButton1.Visible = false;

                UUser  usua      = new UUser();
                LUser  datas     = new LUser();
                String correo    = Session["correo"].ToString();
                String user_name = Session["user_name"].ToString();

                DataTable dat = user.verificarRegistro(correo);
                if (int.Parse(dat.Rows.Count.ToString()) > 0)
                {
                    emp.User_id   = int.Parse(dat.Rows[0]["user_id"].ToString());
                    emp.User_name = dat.Rows[0]["user_name1"].ToString();
                    emp.Clave     = dat.Rows[0]["clave"].ToString();
                    emp.Session   = Session.SessionID;
                    emp.A         = Session["men"].ToString();
                    emp.B         = Session["men1"].ToString();
                    emp.C         = Session["men2"].ToString();
                    emp.D         = Session["men3"].ToString();

                    usua = user.logear(emp);
                    Session["nombre"]  = (usua.User_name);
                    Session["name"]    = (usua.User_name);
                    Session["user_id"] = (usua.UserId);
                    Response.Redirect(usua.Url);
                }
                else
                {
                    UEmpleados empl = new UEmpleados();
                    empl.Email      = correo;
                    empl.Puntos     = 0;
                    empl.Id_Rol     = 4;
                    empl.User_Name1 = user_name;
                    empl.Clave      = Session["password"].ToString();
                    empl.Rclave     = Session["password"].ToString();
                    empl.Sesiones   = 0;
                    empl.Intentos   = 0;
                    empl.Session    = "a";
                    dato            = datas.insertUsuario(empl);

                    DataTable datos = user.verificarRegistro(correo);
                    emp.User_id   = int.Parse(datos.Rows[0]["user_id"].ToString());
                    emp.User_name = datos.Rows[0]["user_name1"].ToString();
                    emp.Clave     = datos.Rows[0]["clave"].ToString();
                    emp.Session   = Session.SessionID;
                    emp.A         = Session["men"].ToString();
                    emp.B         = Session["men1"].ToString();
                    emp.C         = Session["men2"].ToString();
                    emp.D         = Session["men3"].ToString();

                    usua = user.logear(emp);
                    Session["nombre"]  = (usua.User_name);
                    Session["name"]    = (usua.User_name);
                    Session["user_id"] = (usua.UserId);
                    Response.Redirect(usua.Url);
                }
            }
            catch
            {
            }
        }
        FaceBookConnect.API_Key    = "196078794611552";
        FaceBookConnect.API_Secret = "fb201e558813c89209c150c723cb9b99";
        if (!IsPostBack)
        {
            if (Request.QueryString["error"] == "access_denied")
            {
                ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('Acceso no permitido.')", true);
                return;
            }

            string cod = Request.QueryString["code"];
            if (!string.IsNullOrEmpty(cod))
            {
                ViewState["code"] = cod;

                try
                {
                    string          data         = FaceBookConnect.Fetch(cod, "me?fields=id,name,email");
                    FacebookService facebookuser = new JavaScriptSerializer().Deserialize <FacebookService>(data);
                    facebookuser.PictureUrl = string.Format("http://graph.facebook.com/{0}/picture", facebookuser.Id);
                    //pnlFaceBookUser.Visible = true;
                    //LB_.Text = facebookuser.Id;
                    Session["password"]  = facebookuser.Id;
                    Session["user_name"] = facebookuser.Name;
                    Session["correo"]    = facebookuser.Email;
                    Session["band"]      = true;
                    //profileImage.ImageUrl = facebookuser.PictureUrl;
                    B_Login.Enabled = false;


                    UUser  usua      = new UUser();
                    LUser  datas     = new LUser();
                    String correo    = Session["correo"].ToString();
                    String user_name = Session["user_name"].ToString();

                    DataTable dat = user.verificarRegistro(correo);
                    if (int.Parse(dat.Rows.Count.ToString()) > 0)
                    {
                        emp.User_id   = int.Parse(dat.Rows[0]["user_id"].ToString());
                        emp.User_name = dat.Rows[0]["user_name1"].ToString();
                        emp.Clave     = dat.Rows[0]["clave"].ToString();
                        emp.Session   = Session.SessionID;
                        emp.A         = Session["men"].ToString();
                        emp.B         = Session["men1"].ToString();
                        emp.C         = Session["men2"].ToString();
                        emp.D         = Session["men3"].ToString();

                        usua = user.logear(emp);
                        Session["nombre"]  = (usua.User_name);
                        Session["name"]    = (usua.User_name);
                        Session["user_id"] = (usua.UserId);
                        Response.Redirect(usua.Url);
                    }
                    else
                    {
                        UEmpleados empl = new UEmpleados();
                        empl.Email      = correo;
                        empl.Puntos     = 0;
                        empl.Id_Rol     = 4;
                        empl.User_Name1 = user_name;
                        empl.Clave      = Session["password"].ToString();
                        empl.Rclave     = Session["password"].ToString();
                        empl.Sesiones   = 0;
                        empl.Intentos   = 0;
                        empl.Session    = "a";
                        dato            = datas.insertUsuario(empl);

                        DataTable datos = user.verificarRegistro(correo);
                        emp.User_id   = int.Parse(datos.Rows[0]["user_id"].ToString());
                        emp.User_name = datos.Rows[0]["user_name1"].ToString();
                        emp.Clave     = datos.Rows[0]["clave"].ToString();
                        emp.Session   = Session.SessionID;
                        emp.A         = Session["men"].ToString();
                        emp.B         = Session["men1"].ToString();
                        emp.C         = Session["men2"].ToString();
                        emp.D         = Session["men3"].ToString();

                        usua = user.logear(emp);
                        Session["nombre"]  = (usua.User_name);
                        Session["name"]    = (usua.User_name);
                        Session["user_id"] = (usua.UserId);
                        Response.Redirect(usua.Url);
                    }
                }
                catch
                {
                }
            }
        }
    }
예제 #2
0
    protected void Button8_Click(object sender, EventArgs e)
    {
        LIdioma  idioma = new LIdioma();
        UIdioma  com    = new UIdioma();
        LUser    user   = new LUser();
        UUser    emp    = new UUser();
        UUsuario dato   = new UUsuario();
        LUsuario luser  = new LUsuario();

        try
        {
            SRGamesCol.Facebook_servideSoapClient etiqueta = new SRGamesCol.Facebook_servideSoapClient();

            SRGamesCol.ServiceToken seguridad = new SRGamesCol.ServiceToken()
            {
                sToken = "platoweb0pAy3jMuqHXIBV0H2y5v"
            };

            string sToken = etiqueta.AutenticacionCliente(seguridad);

            if (sToken.Equals("-1"))
            {
                Response.Write("<Script Language='JavaScript'>parent.alert('Token invalido');</Script>");
                throw new Exception("token invalido");
            }
            seguridad.AutenticacionToken = sToken;

            DataSet login = etiqueta.loggin(seguridad, UserName.Text.ToString(), Password.Text.ToString());
            GridView1.DataSource = login;
            GridView1.DataBind();
            DataTable p  = login.Tables[0];
            String    da = JsonConvert.SerializeObject(login);
            emp           = JsonConvert.DeserializeObject <UUser>(da);
            emp.Nombre    = p.Rows[0]["nombre"].ToString();
            emp.Email     = p.Rows[0]["correo"].ToString();
            emp.Clave     = Password.Text.ToString();
            emp.User_name = UserName.Text.ToString();


            try
            {
                UUser     usua  = new UUser();
                LUser     datas = new LUser();
                DataTable dat   = user.verificarRes(emp.User_name);
                if (int.Parse(dat.Rows.Count.ToString()) > 0)
                {
                    emp.User_id   = int.Parse(dat.Rows[0]["user_id"].ToString());
                    emp.User_name = dat.Rows[0]["user_name1"].ToString();
                    emp.Clave     = dat.Rows[0]["clave"].ToString();
                    emp.Session   = Session.SessionID;
                    emp.A         = Session["men"].ToString();
                    emp.B         = Session["men1"].ToString();
                    emp.C         = Session["men2"].ToString();
                    emp.D         = Session["men3"].ToString();

                    usua = user.logear(emp);
                    Session["nombre"]  = (usua.User_name);
                    Session["name"]    = (usua.User_name);
                    Session["user_id"] = (usua.UserId);
                    Response.Redirect(usua.Url);
                }
                else
                {
                    UEmpleados empl = new UEmpleados();
                    empl.Email      = emp.Email;
                    empl.Nombre     = emp.Nombre;
                    empl.Puntos     = 0;
                    empl.Id_Rol     = 4;
                    empl.User_Name1 = emp.User_name;
                    empl.Clave      = emp.Clave;
                    empl.Rclave     = emp.Clave;
                    empl.Sesiones   = 0;
                    empl.Intentos   = 0;
                    empl.Session    = "a";
                    dato            = datas.insertUsuario(empl);

                    DataTable datos = user.verificarRes(emp.User_name);
                    emp.User_id   = int.Parse(datos.Rows[0]["user_id"].ToString());
                    emp.User_name = datos.Rows[0]["user_name1"].ToString();
                    emp.Clave     = datos.Rows[0]["clave"].ToString();
                    emp.Session   = Session.SessionID;
                    emp.A         = Session["men"].ToString();
                    emp.B         = Session["men1"].ToString();
                    emp.C         = Session["men2"].ToString();
                    emp.D         = Session["men3"].ToString();

                    usua = user.logear(emp);
                    Session["nombre"]  = (usua.User_name);
                    Session["name"]    = (usua.User_name);
                    Session["user_id"] = (usua.UserId);
                    Response.Redirect(usua.Url);
                }
            }
            catch
            {
            }
        }
        catch (Exception ex)
        {
            Response.Write("<Script Language='JavaScript'>parent.alert('" + ex.Message + "');</Script>");
        }
    }