public bool LoginUser(int Id, string UnicKey) { var users = new B_Users().GetUsers(Id, UnicKey); if (users == null) { return(false); } var finalUser = B_PublicFunctions.GenericMaper <M_Users, V_Users>(new List <M_Users> { users }).FirstOrDefault(); finalUser.ConnectionId = Context.ConnectionId; Users.Add(finalUser); return(true); }
/// <summary> /// ساخت مدل تصویر امنیتی /// </summary> /// <returns>مدل ساخت شده</returns> private MFCaptcha CreateCaptchaObject() { MFCaptcha cp = new MFCaptcha(); string captchaString = B_PublicFunctions.RandomString(6); System.Drawing.Bitmap bmp = B_PublicFunctions.CreateImage(captchaString, Server.MapPath("~/Areas/Admin/Fonts/Captcha.ttf")); using (MemoryStream stream = new MemoryStream()) { bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Png); stream.Close(); cp.ImageContent = stream.ToArray(); } cp.TextValue = captchaString; Session[MFSessions.CAPTCHA_KEY] = cp; return(cp); }
public M_Personels LoginPersonel(string Username, string Password) { var personel = new B_Personels().GetPersonelByUserName(Username, Password); if (personel == null) { return(null); } var finalPersonel = B_PublicFunctions.GenericMaper <M_Personels, V_Personels>(new List <M_Personels> { personel }).FirstOrDefault(); finalPersonel.ConnectionId = Context.ConnectionId; Personels.Add(finalPersonel); return(personel); }
public ActionResult LoginSubmit(string PhoneNumber, string Password) { object result = ""; try { PhoneNumber = B_PublicFunctions.ReplacePersianNums(PhoneNumber); Password = B_PublicFunctions.ReplacePersianNums(Password); if (string.IsNullOrEmpty(PhoneNumber)) { throw F_ExeptionFactory.MakeExeption("نام کاربری را وارد کنید", ((int)E_ErrorCodes.USERNAME_OR_PASSWORD) + S_Seprators.ErrorFieldNameSeprator.ToString() + "UserName", E_LogType.SYSTEM_ERROR); } if (string.IsNullOrEmpty(Password)) { throw F_ExeptionFactory.MakeExeption("گذرواژه را وارد کنید", ((int)E_ErrorCodes.USERNAME_OR_PASSWORD) + S_Seprators.ErrorFieldNameSeprator.ToString() + "Password", E_LogType.SYSTEM_ERROR); } var user = new B_Personels().GetPersonelByUserName(PhoneNumber, Password); if (user == null) { throw F_ExeptionFactory.MakeExeption("نام کاربری یا گذرواژه صحیح نسیت", ((int)E_ErrorCodes.NOT_FOUND) + S_Seprators.ErrorFieldNameSeprator.ToString() + "User", E_LogType.SYSTEM_ERROR); } HttpCookie Coki = new HttpCookie(MFCookies.BOOTH_RIDER_KEY); Coki.Value = user.UnicKey.ToString(); Coki.Expires = DateTime.Now.AddYears(1); Response.Cookies.Add(Coki); } catch (Exception ex) { M_SystemLog exx = new M_SystemLog(E_SystemType.SHAHRDARI_BOOTH_RIDER_APPLICATION, E_LogType.ERROR, ex); result = "Error"; if (ex.Source == E_LogType.SYSTEM_ERROR.ToString()) { exx.LogType = E_LogType.SYSTEM_ERROR; result = exx; } L_Log.SubmitLog(exx); } return(Json(result)); }
public IHttpActionResult GetAllCategories() { try { B_ServicesCategories bCategory = new B_ServicesCategories(); var category = B_PublicFunctions.GenericMaper <M_ServicesCategories, V_ServicesCategories>(bCategory.GetServicesCategories(false)); category = prepareCategoryViewModel(0, category); return(Json(PrepareSuccessResult(category))); } catch (Exception ex) { M_SystemLog exx = new M_SystemLog(E_SystemType.SHAHRDARI_WEB_APPLICATION, E_LogType.ERROR, ex); if (ex.Source == E_LogType.SYSTEM_ERROR.ToString()) { exx.LogType = E_LogType.SYSTEM_ERROR; } L_Log.SubmitLog(exx); if (ex.Source != E_LogType.SYSTEM_ERROR.ToString()) { return(Json(PrepareFaildResult("خطایی در سرور وجود دارد", (int)E_ErrorCodes.SERVER_ERROR + S_Seprators.ErrorFieldNameSeprator.ToString() + ""))); } return(Json(PrepareFaildResult(exx.LogMessage, ex.HelpLink))); } }
public ActionResult Login(string PhoneNumber, string Password) { object result = ""; try { PhoneNumber = B_PublicFunctions.ReplacePersianNums(PhoneNumber); Password = B_PublicFunctions.ReplacePersianNums(Password); if (string.IsNullOrEmpty(PhoneNumber)) { throw F_ExeptionFactory.MakeExeption("نام کاربری را وارد کنید", ((int)E_ErrorCodes.USERNAME_OR_PASSWORD) + S_Seprators.ErrorFieldNameSeprator.ToString() + "UserName", Enums.Loging.E_LogType.SYSTEM_ERROR); } if (string.IsNullOrEmpty(Password)) { throw F_ExeptionFactory.MakeExeption("گذرواژه را وارد کنید", ((int)E_ErrorCodes.USERNAME_OR_PASSWORD) + S_Seprators.ErrorFieldNameSeprator.ToString() + "Password", Enums.Loging.E_LogType.SYSTEM_ERROR); } if (PhoneNumber.Length != 11) { throw F_ExeptionFactory.MakeExeption("گذرواژه وارد شده صحیح نمیباشد", ((int)E_ErrorCodes.USERNAME_OR_PASSWORD) + S_Seprators.ErrorFieldNameSeprator.ToString() + "Password", Enums.Loging.E_LogType.SYSTEM_ERROR); } var user = new B_Users().GetUsers(PhoneNumber); if (user == null) { throw F_ExeptionFactory.MakeExeption("چنین کاربری یافت نشد", ((int)E_ErrorCodes.NOT_FOUND) + S_Seprators.ErrorFieldNameSeprator.ToString() + "User", Enums.Loging.E_LogType.SYSTEM_ERROR); } if (user.IsDeleted == true) { throw F_ExeptionFactory.MakeExeption("چنین کاربری یافت نشد", ((int)E_ErrorCodes.NOT_FOUND) + S_Seprators.ErrorFieldNameSeprator.ToString() + "User", Enums.Loging.E_LogType.SYSTEM_ERROR); } if (user.Password == Password && user.IsActive == false) { B_SmsAuthorise bSms = new B_SmsAuthorise(); var code = bSms.AddCode(PhoneNumber); new ApplicationHelper.Sms().SendSms(PhoneNumber, code.ToString()); result = new { IsActive = false, SmsId = bSms.GetSmsDetailsId(PhoneNumber), UserId = user.Id }; } else if (user.Password == Password && user.IsActive) { result = new { IsActive = true, SmsId = 0, UserId = user.Id } } ; else { throw F_ExeptionFactory.MakeExeption("نام کاربری یا گذرواژه صحیح نمیباشد", ((int)E_ErrorCodes.USERNAME_OR_PASSWORD) + S_Seprators.ErrorFieldNameSeprator.ToString() + "UserNameOrPassword", Enums.Loging.E_LogType.SYSTEM_ERROR); } HttpCookie Coki = new HttpCookie(MFCookies.END_USER_KEY); Coki.Value = user.UnicKey.ToString(); Coki.Expires = DateTime.Now.AddYears(1); Response.Cookies.Add(Coki); } catch (Exception ex) { M_SystemLog exx = new M_SystemLog(E_SystemType.SHAHRDARI_USER_WEB_APPLICATION, E_LogType.ERROR, ex); result = "Error"; if (ex.Source == E_LogType.SYSTEM_ERROR.ToString()) { exx.LogType = E_LogType.SYSTEM_ERROR; result = exx; } L_Log.SubmitLog(exx); } return(Json(result)); }
public ActionResult Register(string Name, string Family, int InstituteType, string MobileNumber, string AsignCode, string Password) { object result = ""; try { MobileNumber = B_PublicFunctions.ReplacePersianNums(MobileNumber); AsignCode = B_PublicFunctions.ReplacePersianNums(AsignCode); Password = B_PublicFunctions.ReplacePersianNums(Password); if (string.IsNullOrEmpty(Name)) { throw F_ExeptionFactory.MakeExeption("لطفا نام را وارد کنید", ((int)E_ErrorCodes.NOT_FOUND) + S_Seprators.ErrorFieldNameSeprator.ToString() + "Name", Enums.Loging.E_LogType.SYSTEM_ERROR); } if (string.IsNullOrEmpty(Family)) { throw F_ExeptionFactory.MakeExeption("لطفا نام خانوادگی را وارد کنید", ((int)E_ErrorCodes.NOT_FOUND) + S_Seprators.ErrorFieldNameSeprator.ToString() + "Family", Enums.Loging.E_LogType.SYSTEM_ERROR); } if (string.IsNullOrEmpty(MobileNumber)) { throw F_ExeptionFactory.MakeExeption("لطفا شماره تلفن همراه را وارد کنید", ((int)E_ErrorCodes.NOT_FOUND) + S_Seprators.ErrorFieldNameSeprator.ToString() + "MobileNumber", Enums.Loging.E_LogType.SYSTEM_ERROR); } if (string.IsNullOrEmpty(Name)) { throw F_ExeptionFactory.MakeExeption("لطفا گذرواژه را وارد کنید", ((int)E_ErrorCodes.NOT_FOUND) + S_Seprators.ErrorFieldNameSeprator.ToString() + "Password", Enums.Loging.E_LogType.SYSTEM_ERROR); } if (!B_PublicFunctions.IsValidPhone(MobileNumber, true)) { throw F_ExeptionFactory.MakeExeption("شماره تلفن همراه وارد شده صحیح نمیباشد", ((int)E_ErrorCodes.NOT_FOUND) + S_Seprators.ErrorFieldNameSeprator.ToString() + "MobileNumber", Enums.Loging.E_LogType.SYSTEM_ERROR); } M_Users mUser = new M_Users(); mUser.FirstName = Name; mUser.LastName = Family; mUser.InstituteType = (E_PublicCategory.INSTITUTE_TYPE)InstituteType; mUser.MobileNumber = MobileNumber; mUser.ReagentCode = string.IsNullOrEmpty(AsignCode) ? 0 : int.Parse(AsignCode); mUser.RegisterDate = DateTime.Now; mUser.LastOnline = DateTime.Now; mUser.IsActive = false; mUser.IsDeleted = false; mUser.UnicKey = Guid.NewGuid().ToString(); mUser.Password = Password; mUser.UserType = E_PublicCategory.USER_TYPE.HOME_STORE; mUser.ReagentUserId = string.IsNullOrEmpty(AsignCode) ? null : (int?)(new B_Users().GetUserByReagentCode(int.Parse(AsignCode)).Id); var res = new B_Users().Add(mUser); if (mUser.ReagentUserId.HasValue) { new B_ServicesRequestItems().Add(new M_ServicesRequestItems { CategoryId = 0, CreateDate = DateTime.Now, ImageName = "Default.jpg", IsFailed = false, RequestId = -5001, ScorePerUnit = 200, ScorePerUnitDriver = 200, Title = $"معرفی {mUser.FirstName} {mUser.LastName} به سیستم", Unit = "عدد", UserType = E_PublicCategory.SYSTEM_USER_TYPE.NORMAL_USER, Value = 1, UserId = mUser.ReagentUserId.Value }); } B_SmsAuthorise bSms = new B_SmsAuthorise(); var code = bSms.AddCode(MobileNumber); new ApplicationHelper.Sms().SendSms(MobileNumber, code.ToString()); result = bSms.GetSmsDetailsId(MobileNumber); } catch (Exception ex) { M_SystemLog exx = new M_SystemLog(E_SystemType.SHAHRDARI_USER_WEB_APPLICATION, E_LogType.ERROR, ex); result = "Error"; if (ex.Source == E_LogType.SYSTEM_ERROR.ToString()) { exx.LogType = E_LogType.SYSTEM_ERROR; result = exx; } L_Log.SubmitLog(exx); } return(Json(result)); }