public object Login() { string Email = HttpContext.Current.Request.Form["Email"]; string Password = HttpContext.Current.Request.Form["Password"]; var data = db.Users.Where(p => p.Role.Id != 1).Where(p => p.Email == Email).FirstOrDefault(); if (data == null) { return(new { Message = 1 }); } if (!DevOne.Security.Cryptography.BCrypt.BCryptHelper.CheckPassword(Password, data.Password)) { return(new { Message = 2 }); } if (data.Status == false) { return(new { Message = 3 }); } if (data.LinkStatus == false) { string key = Guid.NewGuid().ToString().Replace('-', '0').Substring(0, 4); ConfirmEmail c = new ConfirmEmail(); c.Key = key; c.User = data; db.ConfirmEmails.Add(c); SendServiceClient sms = new SmsService.SendServiceClient(); long[] recId = null; byte[] status = null; int res = sms.SendSMS("m.atrincom.com", "61758", "10009611", new string[] { data.Mobile.ToString() }, c.Key, false, ref recId, ref status); // } sms.Close(); if (res == 0) { db.SaveChanges(); } else { return new { Message = -4 } }; return(new { Message = 4 }); } return(new { Message = 0, Api_Token = data.Api_Token }); }
public ActionResult SignIn(User user) { if (user.Password == "" || user.Password == null || user.Email == "" || user.Email == null) { ModelState.Clear(); ModelState.AddModelError("", "نام کاربری یا رمز عبور صحیح نیست"); return(View("Login")); } var u = db.Users.Include("Role").Where(p => p.Email == user.Email).Where(p => p.Role.RoleNameEn == "Member").FirstOrDefault(); if (u == null) { ModelState.Clear(); ModelState.AddModelError("", "نام کاربری یا رمز عبور صحیح نیست"); return(View("Login")); } if (!DevOne.Security.Cryptography.BCrypt.BCryptHelper.CheckPassword(user.Password, u.Password)) { ModelState.Clear(); ModelState.AddModelError("", "نام کاربری یا رمز عبور صحیح نیست"); return(View("Login")); } if (u.Status == false) { ModelState.Clear(); ModelState.AddModelError("", "ورود غیر مجاز"); return(View("Login")); } if (u.LinkStatus == false) { SendServiceClient sms = new SmsService.SendServiceClient(); long[] recId = null; byte[] status = null; string key = Guid.NewGuid().ToString().Replace('-', '0').Substring(0, 4); ConfirmEmail c = new ConfirmEmail(); c.Key = key; c.User = user; db.ConfirmEmails.Add(c); var res = sms.SendSMS("m.atrincom.com", "61758", "10009611", new string[] { user.Mobile.ToString() }, key, false, ref recId, ref status); sms.Close(); if (res == 0) { db.SaveChanges(); } else { ViewBag.Message = "متاسفانه امکان ثبت نام وجود ندارد"; } return(Redirect("/User/Verify")); } FormsAuthentication.SetAuthCookie(u.Email, false); var url = Request["Url"]; if (url != null && url.Trim() != "") { return(Redirect(url)); } return(Redirect("/Home/Index")); }
public object Store() { string Fullname = Request["Fullname"].Trim(); string Password = Request["Password"].Trim(); string Email = Request["Email"].Trim(); string Address = Request["Address"].Trim(); string PhoneNumber = Request["Phone"].Trim(); string Mobile = Request["Mobile"].Trim(); string PostalCode = Request["PostalCode"].Trim(); Role r = db.Roles.Where(p => p.RoleNameEn == "Member").FirstOrDefault(); var user = new User(); user.Role = r; user.Status = true; user.Api_Token = Guid.NewGuid().ToString().Replace('-', '0'); user.Password = DevOne.Security.Cryptography.BCrypt.BCryptHelper.HashPassword(Password, DevOne.Security.Cryptography.BCrypt.BCryptHelper.GenerateSalt()); user.Email = Email; user.Mobile = Mobile; user.PostalCode = PostalCode; user.Fullname = Fullname; user.Address = Address; user.PhoneNumber = PhoneNumber; ViewBag.User = user; if (Email == null || Email == "") { ModelState.AddModelError("", "ایمیل را وارد کنید"); return(View("Register")); } if (Password == null || Password == "") { ModelState.AddModelError("", "کلمه عبور را وارد کنید"); return(View("Register")); } if (Fullname == null || Fullname == "") { ModelState.AddModelError("", "نام را وارد کنید"); return(View("Register")); } if (Address == null || Address == "") { ModelState.AddModelError("", "آدرس را وارد کنید"); return(View("Register")); } if (PostalCode == null || PostalCode == "") { ModelState.AddModelError("", "کدپستی را وارد کنید"); return(View("Register")); } if (PostalCode.Trim().Length != 10) { ModelState.AddModelError("", "کدپستی باید ده رقم باشد"); return(View("Register")); } long nnn2; if (long.TryParse(PostalCode, out nnn2) == false) { ModelState.AddModelError("", "کدپستی باید عدد باشد"); return(View("Register")); } if (!long.TryParse(PhoneNumber, out nnn2)) { ModelState.AddModelError("", "تلفن باید عدد باشد"); return(View("Register")); } if (!long.TryParse(Mobile, out nnn2)) { ModelState.AddModelError("", "موبایل باید عدد باشد"); return(View("Register")); } if (PhoneNumber == null || PhoneNumber == "") { ModelState.AddModelError("", "شماره تلفن را وارد کنید"); return(View("Register")); } if (Mobile == null || Mobile == "") { ModelState.AddModelError("", "موبایل را وارد کنید"); return(View("Register")); } if (db.Users.Any(p => p.Email == Email)) { ModelState.AddModelError("", "ایمیل تکراری است"); return(View("Register")); } if (db.Users.Any(p => p.Mobile == Mobile)) { ModelState.AddModelError("", "تلفن همراه تکراری است"); return(View("Register")); } try { MailAddress m = new MailAddress(Email); } catch { ModelState.AddModelError("", "فرمت ایمیل صحیح نیست"); return(View("Register")); } db.Users.Add(user); //var setting = db.Settings.First(); //if (setting.Email == null || setting.Email.Trim() == "") //{ // user.LinkStatus = true; // ViewBag.Message = "registered"; // db.SaveChanges(); //} //else //{ //SendEmail s = new Utility.SendEmail(setting); string key = Guid.NewGuid().ToString().Replace('-', '0').Substring(0, 4); ConfirmEmail c = new ConfirmEmail(); c.Key = key; c.User = user; db.ConfirmEmails.Add(c); //var list = new List<string>(); //list.Add(user.Email); // var body = "<div>لینک فعالسازی <br> برروی <a target='_blank' href='" + setting.Domain + "/User/ActiveLink/" + key + "'>این لینک</a><span> جهت فعالسازی حساب کاربری خود کلیک کنید</span></div>"; // s.Send(body, "لینک فعالسازی", list); SendServiceClient sms = new SmsService.SendServiceClient(); long[] recId = null; byte[] status = null; var s = sms.SendSMS("m.atrincom.com", "61758", "10009611", new string[] { user.Mobile.ToString() }, c.Key, false, ref recId, ref status); // } sms.Close(); if (s == 0) { db.SaveChanges(); } else { ViewBag.Message = "متاسفانه امکان ثبتنام وجود ندارد"; } return(View("Verify")); }
public object Register() { string Fullname = HttpContext.Current.Request.Form["Fullname"]; string Password = HttpContext.Current.Request.Form["Password"]; string Email = HttpContext.Current.Request.Form["Email"]; string Address = HttpContext.Current.Request.Form["Address"]; string PhoneNumber = HttpContext.Current.Request.Form["PhoneNumber"]; string Mobile = HttpContext.Current.Request.Form["Mobile"]; string PostalCode = HttpContext.Current.Request.Form["PostalCode"]; var setting = db.Settings.FirstOrDefault(); if (db.Users.Any(p => p.Email == Email)) { return(new { Message = 1, }); } if (db.Users.Any(p => p.Mobile == Mobile)) { return(new { Message = 2, }); } Role r = db.Roles.Where(p => p.RoleNameEn == "Member").FirstOrDefault(); var user = new User(); user.Role = r; user.Status = true; user.LinkStatus = false; SendEmail s = new Utility.SendEmail(setting); string key = Guid.NewGuid().ToString().Replace('-', '0').Substring(0, 4); ConfirmEmail c = new ConfirmEmail(); c.Key = key; c.User = user; db.ConfirmEmails.Add(c); user.Api_Token = Guid.NewGuid().ToString().Replace('-', '0').Substring(0, 4); user.Password = DevOne.Security.Cryptography.BCrypt.BCryptHelper.HashPassword(Password, DevOne.Security.Cryptography.BCrypt.BCryptHelper.GenerateSalt()); user.Email = Email; user.Fullname = Fullname; user.Address = Address; user.PhoneNumber = PhoneNumber; db.Users.Add(user); SendServiceClient sms = new SmsService.SendServiceClient(); long[] recId = null; byte[] status = null; int res = sms.SendSMS("m.atrincom.com", "61758", "10009611", new string[] { user.Mobile.ToString() }, c.Key, false, ref recId, ref status); sms.Close(); if (res == 0) { db.SaveChanges(); } else { return new { Message = "امکان ثبت نام وجود ندارد" } }; db.SaveChanges(); return(new { Message = 0 }); }