private async void OnLogin() { var model = new adminModel { Username = Username, Password = Password }; var json = System.Text.Json.JsonSerializer.Serialize(model); var data = new StringContent(json, Encoding.UTF8, "application/json"); using var client = new HttpClient(); var result = await client.PostAsync("http://codehub.pythonanywhere.com/api/v1/admin/login", data); MessageBox.Show(result.Content.ReadAsStringAsync().Result); }
public static adminModel getAdminById(int id) { string sql = "select * from admin where id=@id"; MySqlParameter[] para = new MySqlParameter[] { new MySqlParameter("@id", MySqlDbType.Int16) }; DataSet ds = MysqlHelper.ExcuteReader(sql, para); adminModel adminM = new adminModel(); if (ds != null) { adminM.Id = (int)ds.Tables[0].Rows[0]["id"]; adminM.Password = (int)ds.Tables[0].Rows[0]["id"]; } }
public ActionResult login(adminModel model) { using (var context = new promoLacDbEntities()) { bool isvalidVendor = context.mainAdmins.Any(x => x.username == model.username && x.password_ == model.password_); if (isvalidVendor) { FormsAuthentication.SetAuthCookie(model.username, false); return(RedirectToAction("addVendor", "Vendor")); } ModelState.AddModelError("", "Invalid User Name and Password"); } return(View()); }
public ActionResult AdminGiris(adminModel model) { try { var admin = db.Admin.Where(s => s.kullanici_adi == model.kullanici_adi && s.sifre == model.sifre).Single(); Session.Add("admin", admin.kullanici_adi); return(new RedirectResult(@"~\Home\AdminGiris")); } catch { TempData["mesaj"] = "Hatalı Kullanıcı Adı veya Şifre"; return(new RedirectResult(@"~\Home\AdminGiris")); } }
public AuthModel FinishEditing([FromBody] adminModel model) { var nlea = _readOnlyRepository.FirstOrDefault <League>(x => x.Id == model.Id); nlea.Name = model.Name; nlea.Day = model.Day; nlea.Location = model.Location; var eLeague = nlea; var editLeague = _writeOnlyRepository.Update(eLeague); var authModel = new AuthModel { }; return(authModel); }
public AuthModel admin([FromBody] adminModel model) { League lea = new League(); lea.Name = model.Name; lea.Day = model.Day; lea.Location = model.Location; var newLeague = lea; var createdLeague = _writeOnlyRepository.Create(newLeague); var authModel = new AuthModel { }; return(authModel); }
public void deleteLeague([FromBody] adminModel model) { _writeOnlyRepository.Delete <League>(model.Id); }
// GET: AdminPanel public ActionResult AdminPanel() { if (globalVariable.loggedin) { ViewBag.loggedin = true; ViewBag.username = globalVariable.username; ViewBag.admin = globalVariable.admin; } var model = new List <adminModel>(); connectionString(); con.Open(); com.Connection = con; //user count com.CommandText = "SELECT COUNT (U_id) FROM user_t"; dr = com.ExecuteReader(); while (dr.Read()) { am.userCount = dr.GetInt32(0); } con.Close(); //qa count con.Open(); com.CommandText = "SELECT COUNT (Qa_id) FROM qa"; dr = com.ExecuteReader(); while (dr.Read()) { am.qaCount = dr.GetInt32(0); } con.Close(); //vid count con.Open(); com.CommandText = "SELECT COUNT (Vid_id) FROM video"; dr = com.ExecuteReader(); while (dr.Read()) { am.vidCount = dr.GetInt32(0); } con.Close(); //msg count MessageController ms = new MessageController(); am.msgCount = ms.msgCount(); model.Add(am); //admin con.Open(); com.CommandText = "SELECT * FROM user_t WHERE Admin_check = '1'"; dr = com.ExecuteReader(); while (dr.Read()) { adminModel adName = new adminModel(); adName.adminUser = Convert.ToString(dr["Username"]); model.Add(adName); } con.Close(); //ban con.Open(); com.CommandText = "SELECT * FROM user_t WHERE ban = '1'"; dr = com.ExecuteReader(); while (dr.Read()) { adminModel banName = new adminModel(); banName.bannedUser = Convert.ToString(dr["Username"]); model.Add(banName); } con.Close(); //tutor con.Open(); com.CommandText = "SELECT * FROM user_t WHERE Rating >= '500'"; dr = com.ExecuteReader(); while (dr.Read()) { adminModel tutorName = new adminModel(); tutorName.tutorUser = Convert.ToString(dr["Username"]); model.Add(tutorName); } con.Close(); return(View(model)); }
public ActionResult register_new(adminModel adminModel) { var error_message = new object(); if (string.IsNullOrWhiteSpace(adminModel.adminName) || string.IsNullOrWhiteSpace(adminModel.adminLastName) || string.IsNullOrWhiteSpace(adminModel.adminPassword) || string.IsNullOrWhiteSpace(adminModel.adminEmail)) { error_message = "error, something went wrong with the request"; return(Json(error_message, "application/json; charset=utf-8", Encoding.UTF8, JsonRequestBehavior.DenyGet)); } List <Admin> admins = new List <Admin>(); using (var api = new HttpClient()) { api.BaseAddress = new Uri("https://localhost:44343/api/admin/"); api.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var get_admin = api.GetAsync("all"); get_admin.Wait(); var result = get_admin.Result; if (result.StatusCode == HttpStatusCode.OK) { var s = result.Content.ReadAsAsync <List <Admin> >(); s.Wait(); admins = s.Result; } else if (result.StatusCode == HttpStatusCode.NotFound) { var s = result.Content.ReadAsAsync <List <Admin> >(); s.Wait(); admins = s.Result; } } if (admins.Count() > 0) { error_message = "error, admin exists"; return(Json(error_message, "application/json; charset=utf-8", Encoding.UTF8, JsonRequestBehavior.DenyGet)); } var salt = EncryptionVerifiers.generate_salt(); var real_password = EncryptionVerifiers.encrypt_value(salt, adminModel.adminPassword); Admin admin = new Admin { Email = adminModel.adminEmail, FirstName = adminModel.adminName, LastName = adminModel.adminLastName, Password = real_password, Salt = salt }; var flag = false; using (var api = new HttpClient()) { api.BaseAddress = new Uri("https://localhost:44343/api/admin/"); api.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var post = api.PostAsJsonAsync <Admin>("new", admin); post.Wait(); var result = post.Result; if (result.StatusCode == HttpStatusCode.Created) { var s = result.Content.ReadAsAsync <bool>(); s.Wait(); flag = s.Result; } else if (result.StatusCode == HttpStatusCode.NotFound) { var s = result.Content.ReadAsAsync <bool>(); s.Wait(); flag = s.Result; } else { error_message = "error, internal server error please try again later"; return(Json(error_message, "application/json; charset=utf-8", Encoding.UTF8, JsonRequestBehavior.DenyGet)); } } if (!flag) { error_message = "error, could not regsiter at this moment, please try again later"; return(Json(error_message, "application/json; charset=utf-8", Encoding.UTF8, JsonRequestBehavior.DenyGet)); } else { //FormsAuthentication.SetAuthCookie(admin.Email, false); error_message = Url.Action("Login", "login"); return(Json(error_message, "application/json; charset=utf-8", Encoding.UTF8, JsonRequestBehavior.DenyGet)); } }