public void resetLoginInfo() { vrlfgysdbEntities db = new vrlfgysdbEntities(); int id = GetCurrentUser.GetUser().id; FormsAuthentication.SignOut(); kullanicilar usr = db.kullanicilar.Where(e => e.id == id).FirstOrDefault(); if (usr != null) { LoggedUserModel loggedUser = new LoggedUserModel(); foreach (var property in loggedUser.GetType().GetProperties()) { try { var response = usr.GetType().GetProperty(property.Name).GetValue(usr, null).ToString(); if (response == null && property.PropertyType != typeof(int)) { if (response == null) { continue; } } else { PropertyInfo propertyS = loggedUser.GetType().GetProperty(property.Name); if (property.PropertyType == typeof(decimal)) { propertyS.SetValue(loggedUser, Convert.ChangeType(Decimal.Parse(response.Replace('.', ',')), property.PropertyType), null); } else if (property.PropertyType == typeof(int)) { if (response == null) { propertyS.SetValue(loggedUser, Convert.ChangeType(0, property.PropertyType), null); } else { propertyS.SetValue(loggedUser, Convert.ChangeType(Decimal.Parse(response.Replace('.', ',')), property.PropertyType), null); } } else { propertyS.SetValue(loggedUser, Convert.ChangeType(response, property.PropertyType), null); } } } catch (Exception) { } } Guid gd = new Guid(); gd = Guid.NewGuid(); string query = "select * from firma_musavir where flag = " + durumlar.aktif.ToString() + " and id = " + loggedUser.firma_id; FirmaMusavirModel fmm = db.Database.SqlQuery <FirmaMusavirModel>(query).FirstOrDefault(); loggedUser.fm = fmm; SetAuthCookie(gd.ToString(), true, loggedUser); } }
public string yeniKullanici(string password, string password_control, string mail_permission, string sms_permission, HttpRequestBase Request) { try { vrlfgysdbEntities db = new vrlfgysdbEntities(); int mailPermission = Permissions.granted; if (mail_permission == null) { mailPermission = Permissions.denied; } int smsPermission = Permissions.granted; if (sms_permission == null) { smsPermission = Permissions.denied; } int vid = 1; if (db.kullanicilar.Count() != 0) { vid = db.kullanicilar.Max(e => e.vid) + 1; } int sort = 1; if (db.kullanicilar.Count() != 0) { sort = db.kullanicilar.Max(e => e.sort) + 1; } kullanicilar user = new kullanicilar(); foreach (var property in user.GetType().GetProperties()) { try { var response = Request[property.Name]; if (response == null && property.PropertyType != typeof(int)) { if (response == null) { continue; } } else { PropertyInfo propertyS = user.GetType().GetProperty(property.Name); if (property.PropertyType == typeof(decimal)) { propertyS.SetValue(user, Convert.ChangeType(Decimal.Parse(response.Replace('.', ',')), property.PropertyType), null); } else if (property.PropertyType == typeof(int)) { if (response == null) { propertyS.SetValue(user, Convert.ChangeType(0, property.PropertyType), null); } else { propertyS.SetValue(user, Convert.ChangeType(Decimal.Parse(response.Replace('.', ',')), property.PropertyType), null); } } else { propertyS.SetValue(user, Convert.ChangeType(response, property.PropertyType), null); } } } catch (Exception) { } } string strImageName = StringFormatter.OnlyEnglishChar(user.ad + " " + user.soyad); string createdUrl = strImageName; string tempUrl = createdUrl; bool bulundu = false; int i = 0; kullanicilar pg = new kullanicilar(); do { pg = db.kullanicilar.Where(e => e.url.Equals(tempUrl)).FirstOrDefault(); if (pg != null) { tempUrl = tempUrl + i.ToString(); } else { createdUrl = tempUrl; bulundu = true; } i++; } while (!bulundu); user.url = createdUrl; user.mail_permission = mailPermission; user.sms_permission = smsPermission; user.password = HashWithSha.ComputeHash(password, "SHA512", Encoding.ASCII.GetBytes(password)); user.flag = durumlar.emailOnayBekliyor; user.date = DateTime.Now; user.vid = vid; user.reset_guidexpiredate = DateTime.Now.AddDays(5); user.ekleyen = GetCurrentUser.GetUser().id; //user.kullanici_turu = KullaniciTurleri.super_admin; user.sort = sort; user.mail_host = ""; user.mail_port = ""; user.mail_ssl = ""; user.mail_psw = ""; Guid gd = new Guid(); gd = Guid.NewGuid(); user.reset_guid = gd.ToString(); LoggedUserModel lgm = GetCurrentUser.GetUser(); int incelenecekKullaniciTurleri = lgm.kullanici_turu; if (lgm.kullanici_turu == KullaniciTurleri.super_admin) { incelenecekKullaniciTurleri = 0; } if (!(user.kullanici_turu > incelenecekKullaniciTurleri)) { return(""); } bool kullaniciKontrol = firmaKullaniciKontrol(user.firma_id, user.id).Result; if (!kullaniciKontrol) { return("kullanici_sayisi_hatasi"); } db.kullanicilar.Add(user); db.SaveChanges(); string icerik = "<div>Üyeliğiniz Oluşturulmuştur.</div>" + "<div>Üyeliğiniz başarı ile oluşturulmuştur. Aşağıdaki onay linkine tıklayarak üyeliğinizi onaylayailrsiniz. Bizi tercih ettiğiniz için teşekkür ederiz.</div> <div><a href=\"" + config.url + "EmailOnay/" + user.reset_guid + "\">E-mail adresinizi onaylamak için tıklayınız</a></div>"; string baslik = config.projeİsmi + " Üyeliği E-mail Onay"; EmailFunctions.sendEmailGmail(icerik, baslik, user.email, MailHedefTur.kullanici, user.id, EmailFunctions.mailAdresi, 0, "", "", "", "", -3); return(user.url); } catch (Exception e) { if (e.InnerException != null && e.InnerException.ToString().Contains("email_unique")) { return("email_unique"); } else if (e.InnerException != null && e.InnerException.ToString().Contains("username_unique")) { return("username_unique"); } else { return(""); } } }
public JsonResult Index(string username, string password) { /*var response = Request["g-recaptcha-response"]; * if (!validateCaptcha.validateC(response)) * { * return Json(FormReturnTypes.captchaHatasi, JsonRequestBehavior.AllowGet); * }*/ string sifre = HashWithSha.ComputeHash(password, "SHA512", Encoding.ASCII.GetBytes(password)); kullanicilar usr = db.kullanicilar.Where(e => e.username == username && e.password == sifre && e.flag == durumlar.aktif && e.kullanici_turu == KullaniciTurleri.super_admin).FirstOrDefault(); if (usr != null) { LoggedUserModel loggedUser = new LoggedUserModel(); foreach (var property in loggedUser.GetType().GetProperties()) { try { var response = usr.GetType().GetProperty(property.Name).GetValue(usr, null).ToString(); if (response == null && property.PropertyType != typeof(int)) { if (response == null) { continue; } } else { PropertyInfo propertyS = loggedUser.GetType().GetProperty(property.Name); if (property.PropertyType == typeof(decimal)) { propertyS.SetValue(loggedUser, Convert.ChangeType(Decimal.Parse(response.Replace('.', ',')), property.PropertyType), null); } else if (property.PropertyType == typeof(int)) { if (response == null) { propertyS.SetValue(loggedUser, Convert.ChangeType(0, property.PropertyType), null); } else { propertyS.SetValue(loggedUser, Convert.ChangeType(Decimal.Parse(response.Replace('.', ',')), property.PropertyType), null); } } else { propertyS.SetValue(loggedUser, Convert.ChangeType(response, property.PropertyType), null); } } } catch (Exception) { } } Guid gd = new Guid(); gd = Guid.NewGuid(); string query = "select * from firma_musavir where flag = " + durumlar.aktif.ToString() + " and id = " + loggedUser.firma_id; FirmaMusavirModel fmm = db.Database.SqlQuery <FirmaMusavirModel>(query).FirstOrDefault(); loggedUser.fm = fmm; SetAuthCookie(gd.ToString(), true, loggedUser); return(Json(FormReturnTypes.basarili, JsonRequestBehavior.AllowGet)); } else { return(Json(FormReturnTypes.basarisiz, JsonRequestBehavior.AllowGet)); } }
public string kullaniciDuzenle(string url, string password, string password_control, string mail_permission, string sms_permission, HttpRequestBase Request) { try { vrlfgysdbEntities db = new vrlfgysdbEntities(); int mailPermission = Permissions.granted; if (mail_permission == null) { mailPermission = Permissions.denied; } int smsPermission = Permissions.granted; if (sms_permission == null) { smsPermission = Permissions.denied; } LoggedUserModel lgm = GetCurrentUser.GetUser(); int incelenecekKullaniciTurleri = lgm.kullanici_turu; if (lgm.kullanici_turu == KullaniciTurleri.super_admin) { incelenecekKullaniciTurleri = 0; } kullanicilar dbUser = db.kullanicilar.Where(e => e.url.Equals(url) && e.flag != durumlar.silindi && (e.id == lgm.id || e.kullanici_turu > incelenecekKullaniciTurleri)).FirstOrDefault(); if (dbUser == null || url == null || url.Equals("")) { string firmaId = Request["firma_id"].ToString(); if (!firmaId.Equals(lgm.firma_id.ToString())) { return(""); } return(yeniKullanici(password, password_control, mail_permission, sms_permission, Request)); } else if (!(dbUser.flag != durumlar.silindi)) { return(""); } string passwordTemp = dbUser.password; string urlTemp = dbUser.url; //kullanicilar user = new kullanicilar(); foreach (var property in dbUser.GetType().GetProperties()) { try { var response = Request[property.Name]; if (response == null) { if (response == null) { continue; } } else { PropertyInfo propertyS = dbUser.GetType().GetProperty(property.Name); if (property.PropertyType == typeof(decimal)) { propertyS.SetValue(dbUser, Convert.ChangeType(Decimal.Parse(response.Replace('.', ',')), property.PropertyType), null); } else { propertyS.SetValue(dbUser, Convert.ChangeType(response, property.PropertyType), null); } } } catch (Exception) { } } if (!password.Trim().Equals("")) { dbUser.password = HashWithSha.ComputeHash(password, "SHA512", Encoding.ASCII.GetBytes(password)); } else { dbUser.password = passwordTemp; } dbUser.url = urlTemp; if (!(dbUser.id == lgm.id || dbUser.kullanici_turu > incelenecekKullaniciTurleri)) { return(""); } bool kullaniciKontrol = firmaKullaniciKontrol(dbUser.firma_id, dbUser.id).Result; if (!kullaniciKontrol) { return("kullanici_sayisi_hatasi"); } dbUser.mail_permission = mailPermission; dbUser.sms_permission = smsPermission; db.Entry(dbUser).State = EntityState.Modified; db.SaveChanges(); if (dbUser.id == GetCurrentUser.GetUser().id) { kullaniciIslemleri ki = new kullaniciIslemleri(); ki.resetLoginInfo(); } return(dbUser.url); } catch (Exception e) { if (e.InnerException != null && e.InnerException.ToString().Contains("email_unique")) { return("email_unique"); } else if (e.InnerException != null && e.InnerException.ToString().Contains("username_unique")) { return("username_unique"); } else { return(""); } } }
public async Task <CevapModel> KullaniciLogin() { try { vrlfgysdbEntities db = new vrlfgysdbEntities(); var context = new HttpContextWrapper(HttpContext.Current); HttpRequestBase request = context.Request; string gelenJson; using (Stream receiveStream = request.InputStream) { using (StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8)) { gelenJson = readStream.ReadToEnd(); } } KullanicilarModelServis kullanici = JsonConvert.DeserializeObject <KullanicilarModelServis>(gelenJson); kullanici.password = HashWithSha.ComputeHash(kullanici.password, "SHA512", Encoding.ASCII.GetBytes(kullanici.password)); kullanicilar dbKullanici = db.kullanicilar.Where(e => e.flag == durumlar.aktif && e.email.Equals(kullanici.email) && e.password.Equals(kullanici.password)).FirstOrDefault(); if (dbKullanici == null) { return(CreateCevap.cevapOlustur(false, "Yanlış E-mail ya da şifre. Lütfen girdiğiniz bilgileri kontrol ederek tekrar deneyiniz.", null)); } KullanicilarModelServis ym = new KullanicilarModelServis(); foreach (var property in ym.GetType().GetProperties()) { try { var response = dbKullanici.GetType().GetProperty(property.Name).GetValue(dbKullanici, null).ToString(); if (response == null && property.PropertyType != typeof(int)) { if (response == null) { continue; } } else { PropertyInfo propertyS = ym.GetType().GetProperty(property.Name); if (property.PropertyType == typeof(decimal)) { propertyS.SetValue(ym, Convert.ChangeType(Decimal.Parse(response.Replace('.', ',')), property.PropertyType), null); } else if (property.PropertyType == typeof(int)) { if (response == null) { propertyS.SetValue(ym, Convert.ChangeType(0, property.PropertyType), null); } else { propertyS.SetValue(ym, Convert.ChangeType(Decimal.Parse(response.Replace('.', ',')), property.PropertyType), null); } } else { propertyS.SetValue(ym, Convert.ChangeType(response, property.PropertyType), null); } } } catch (Exception) { } } firma_musavir fm = dbKullanici.firma_musavir.FirstOrDefault(); if (fm != null) { ym.konum_periyot = fm.konum_periyot; } else { ym.konum_periyot = 1; } return(CreateCevap.cevapOlustur(true, "", ym)); } catch (Exception ex) { return(CreateCevap.cevapOlustur(false, "Bir hata oluştu. Lütfen tekrar deneyiniz", null)); } }