public List <Userclass> getUsers() { Userclass us; List <Userclass> ls = new List <Userclass>(); try { string str = "getUsers()"; var reult = database.RunCommand <BsonDocument>(new BsonDocument { { "eval", str } }); var array = reult["retval"].AsBsonArray; foreach (var b in array) { us = new Userclass(); us.usersname = b["user"].AsString; us.pass = "******"; us.role = b["roles"][0]["role"].ToString(); if (us.role == "executeEval") { us.role = b["roles"][1]["role"].ToString(); } ls.Add(us); } } catch (Exception e) { MessageBox.Show(e.Message); } return(ls); }
public void GetuserProfile(string accesstoken) { string url = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=" + accesstoken + ""; WebRequest request = WebRequest.Create(url); request.Credentials = CredentialCache.DefaultCredentials; WebResponse response = request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); reader.Close(); response.Close(); JavaScriptSerializer js = new JavaScriptSerializer(); Userclass userinfo = js.Deserialize <Userclass>(responseFromServer); Session["profilepicture"] = userinfo.picture; Session["image-url"] = userinfo.picture; Session["userid"] = userinfo.id; /// lblgender.Text = userinfo.gender; // lbllocale.Text = userinfo.locale; Session["username"] = userinfo.name; Session["userid"] = userinfo.id; // hylprofile.NavigateUrl = userinfo.link; }
public ActionResult FeedBack() { Userclass user = new Userclass(); string rootpath = System.Configuration.ConfigurationManager.AppSettings["rooturl"].ToString(); if (Request.QueryString["code"] != null) { string redirection_url = rootpath + "Home/FeedBack"; user = ium.GetToken(Request.QueryString["code"].ToString(), redirection_url); if (!ium.Checkuser(user.id)) { ium.AddsocalUser(user); } ViewBag.Id = user.id; } else { string clientid = "18165402201-i4hq1sqdt8h4ftph4kf647l551jqp2tu.apps.googleusercontent.com"; //your client secret string clientsecret = "Q_yDKwN32V0lgA9mW6edEvyA"; //your redirection url string redirection_url = rootpath + "Home/FeedBack"; string url = "https://accounts.google.com/o/oauth2/v2/auth?scope=profile&include_granted_scopes=true&redirect_uri=" + redirection_url + "&response_type=code&client_id=" + clientid + ""; Response.Redirect(url); } ViewBag.stations = trepositery.getStations(); return(View()); }
public void GetuserProfile(string accesstoken) { string url = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=" + accesstoken + ""; WebRequest request = WebRequest.Create(url); request.Credentials = CredentialCache.DefaultCredentials; WebResponse response = request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); reader.Close(); response.Close(); JavaScriptSerializer js = new JavaScriptSerializer(); Userclass userinfo = js.Deserialize <Userclass>(responseFromServer); Business.ScsBO sbo = new Business.ScsBO(); Entity.Staff st = sbo.login(userinfo.email); if (st == null || (st.account != userinfo.email || !st.status.Equals("active")) || st.role.Equals("Admin")) { Response.Redirect("~/UI/Login.aspx?status=error"); } Session["account"] = st.staffName; Session["usermail"] = userinfo.email; lbUserName.Text = st.staffName; //set session to check table Session["accountID"] = st.accountID; Session["role"] = st.role; }
public int AddsocalUser(Userclass Userclass) { tblUser user = new tblUser(); user.UserId = Userclass.id; user.Password = "******"; user.ConfirmPassword = "******"; user.Role = 5; user.FirstName = Userclass.given_name; user.LastName = Userclass.family_name; user.CreatedDate = DateTime.Now; user.LastUpdateDate = DateTime.Now; user.Status = "Y"; return(repo.Adduser(user)); }
public void GetuserProfile(string accesstoken) { string url = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=" + accesstoken + ""; WebRequest request = WebRequest.Create(url); request.Credentials = CredentialCache.DefaultCredentials; WebResponse response = request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); reader.Close(); response.Close(); JavaScriptSerializer js = new JavaScriptSerializer(); Userclass userinfo = js.Deserialize <Userclass>(responseFromServer); lblEmail.Text = userinfo.email; }
public void GetuserProfile(string accesstoken) { string url = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=" + accesstoken + ""; WebRequest request = WebRequest.Create(url); request.Credentials = CredentialCache.DefaultCredentials; WebResponse response = request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); reader.Close(); response.Close(); JavaScriptSerializer js = new JavaScriptSerializer(); Userclass userinfo = js.Deserialize <Userclass>(responseFromServer); //imgprofile.ImageUrl = userinfo.picture; to stored image come from google MasterPageFirstName.Text = userinfo.given_name; MasterPageLastName.Text = userinfo.family_name; MasterPageEmail.Text = userinfo.email; //a }
public Userclass GetuserProfile(string accesstoken) { string url = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=" + accesstoken + ""; WebRequest request = WebRequest.Create(url); request.Credentials = CredentialCache.DefaultCredentials; WebResponse response = request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); reader.Close(); response.Close(); JavaScriptSerializer js = new JavaScriptSerializer(); Userclass userinfo = js.Deserialize <Userclass>(responseFromServer); //Userc.ImageUrl = userinfo.picture; //Userc.id = userinfo.id; //Userc.gender = userinfo.gender; //Userc.locale = userinfo.locale; //Userc.name = userinfo.name; //Userc.link = userinfo.link; return(userinfo); }
public Userclass GetToken(string code, string redirection_url) { //your client id string clientid = "18165402201-i4hq1sqdt8h4ftph4kf647l551jqp2tu.apps.googleusercontent.com"; //your client secret string clientsecret = "Q_yDKwN32V0lgA9mW6edEvyA"; //your redirection url //string redirection_url = "http://localhost:50602/Home/Notification"; string url = "https://accounts.google.com/o/oauth2/token"; string poststring = "grant_type=authorization_code&code=" + code + "&client_id=" + clientid + "&client_secret=" + clientsecret + "&redirect_uri=" + redirection_url + ""; var request = (HttpWebRequest)WebRequest.Create(url); request.ContentType = "application/x-www-form-urlencoded"; request.Method = "POST"; UTF8Encoding utfenc = new UTF8Encoding(); byte[] bytes = utfenc.GetBytes(poststring); Stream outputstream = null; try { request.ContentLength = bytes.Length; outputstream = request.GetRequestStream(); outputstream.Write(bytes, 0, bytes.Length); } catch { } var response = (HttpWebResponse)request.GetResponse(); var streamReader = new StreamReader(response.GetResponseStream()); string responseFromServer = streamReader.ReadToEnd(); JavaScriptSerializer js = new JavaScriptSerializer(); var obj = js.Deserialize <Tokenclass>(responseFromServer); Userclass uc = GetuserProfile(obj.access_token); return(uc); }
public ActionResult GoogleCallback(string accesstoken, string token) { Userclass userinfo = new Userclass(); try { string url = "https://www.googleapis.com/oauth2/v1/userinfo?alt=json&access_token=" + accesstoken + ""; WebRequest request = WebRequest.Create(url); request.Credentials = CredentialCache.DefaultCredentials; WebResponse response = request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); reader.Close(); response.Close(); JavaScriptSerializer js = new JavaScriptSerializer(); userinfo = js.Deserialize <Userclass>(responseFromServer); var cus = new Base.Customer { Email = userinfo.email, UserName = userinfo.email, FullName = userinfo.family_name + " " + userinfo.given_name + " " + userinfo.name, DateCreated = DateTime.Now.TotalSeconds(), IsActive = true, IsDelete = false, idUserGoogle = userinfo.id, AvatarUrl = userinfo.picture, TokenDevice = token, }; InsertCustomerGoogle(cus); var customer = customerDA.GetByidUserGoogle(cus.idUserGoogle); var key = Guid.NewGuid(); IAuthContainerModel model = new JWTContainerModel() { Claims = new Claim[] { new Claim(type: "Phone", value: customer.Mobile ?? ""), new Claim(type: "Type", value: "Token"), new Claim(type: "ID", value: customer.ID.ToString()), }, ExpireMinutes = 10, }; IAuthContainerModel modelRefreshToken = new JWTContainerModel() { Claims = new Claim[] { new Claim(type: "Phone", value: customer.Mobile ?? ""), new Claim(type: "Type", value: "RefreshToken"), new Claim(type: "key", value: key.ToString()), new Claim(type: "ID", value: customer.ID.ToString()), }, ExpireMinutes = 60 * 24 * 30, }; var tokenResponse = JWTService.Instance.GenerateToken(model: model); var refreshToken = JWTService.Instance.GenerateToken(model: modelRefreshToken); customerDA.InsertToken(data: new TokenRefresh() { GuidId = key }); customerDA.Save(); return(Json(data: new BaseResponse <CustomerAppIG4Item>() { Code = 200, Erros = false, Message = "", Data = new CustomerAppIG4Item() { Token = tokenResponse, RefreshToken = refreshToken } }, behavior: JsonRequestBehavior.AllowGet)); } catch (Exception e) { return(Redirect("/")); } return(Redirect("/")); }
public void GetuserProfile(string accesstoken) { string url = "https://www.googleapis.com/oauth2/v2/userinfo?alt=json&access_token=" + accesstoken + ""; WebRequest request = WebRequest.Create(url); request.Credentials = CredentialCache.DefaultCredentials; WebResponse response = request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); string responseFromServer = reader.ReadToEnd(); reader.Close(); response.Close(); JavaScriptSerializer js = new JavaScriptSerializer(); Userclass userinfo = js.Deserialize <Userclass>(responseFromServer); //txtMaDangNhap.Text = userinfo.email; //string strMaSV = txtMaDangNhap.Text.Trim(); //string strSql = string.Format("SELECT * FROM [dbo].[AS_Academy_Student] where Code='{0}'", strMaSV); string strSql = string.Format("SELECT * FROM [dbo].[AS_Academy_Student] where EmailNhaTruong=@Param1 and DaXacThucEmailNhaTruong=1"); strSql += string.Format(@"INSERT INTO [dbo].[AS_Logs] ([UserId] ,[UserCode] ,[Status] ,[Code] ,[Message] ,[CreatedTime]) VALUES (-1 ,'{0}' ,1 ,'LOGIN' ,'{2}' ,'{1}') ;", userinfo.email, DateTime.Now, 3); SqlParameter[] sqlParams = new SqlParameter[1]; sqlParams[0] = new SqlParameter("@Param1", userinfo.email); //sqlParams[0].ParameterName = "@Param1"; //sqlParams[0].SqlDbType = SqlDbType.VarChar; //sqlParams[0].Value = strMaSV; DataTable dtData = Microsoft.ApplicationBlocks.Data.SqlHelper.ExecuteDataset(nuce.web.data.Nuce_Common.ConnectionString, CommandType.Text, strSql, sqlParams).Tables[0]; if (dtData != null && dtData.Rows.Count > 0) { nuce.web.model.SinhVien SinhVien = new nuce.web.model.SinhVien(); string strFullName = dtData.Rows[0]["FulName"].ToString(); string[] strFullNames = strFullName.Split(new char[] { ' ' }); SinhVien.Ho = strFullName; SinhVien.Ten = strFullNames[strFullNames.Length - 1]; //SinhVien.TrangThai = int.Parse(dtData.Rows[0]["status"].ToString()); SinhVien.SinhVienID = int.Parse(dtData.Rows[0]["ID"].ToString()); SinhVien.Email = dtData.Rows[0].IsNull("EmailNhaTruong") ? "" : dtData.Rows[0]["EmailNhaTruong"].ToString(); SinhVien.Mobile = dtData.Rows[0]["Mobile"].ToString(); SinhVien.MaSV = dtData.Rows[0]["Code"].ToString(); string File1 = dtData.Rows[0].IsNull("File1") ? "" : dtData.Rows[0]["File1"].ToString(); if (!File1.Trim().Equals("")) { SinhVien.IMG = File1; } else { SinhVien.IMG = "/Data/images/noimage_human.png"; } Session[Utils.session_sinhvien] = SinhVien; Response.Redirect("/DichVuSinhVien.aspx"); } else { spAlert.InnerHtml = string.Format(@"<div class='alert alert-warning alert-dismissible' style='position: absolute; top: 0; right: 0;'> <a href = '#' class='close' data-dismiss='alert' aria-label='close'>×</a> {0}</div>", "Không đúng tên đăng nhập"); } //Kiem tra ho ten xem co trung khong sau do lay trong csdl //imgprofile.ImageUrl = userinfo.picture; //lblid.Text = userinfo.id; //lblgender.Text = userinfo.gender; //lbllocale.Text = userinfo.locale; //lblname.Text = userinfo.name; //hylprofile.NavigateUrl = userinfo.link; }