internal string SendNotification(string mobile, string text, string name, int type) { //var refStr = mobile; //if (refStr[0] == '0') // refStr = refStr.Substring(1); //if (refStr[0] == '9') // refStr = refStr.Substring(1); //refStr += type.ToString(); Magfa m = new Magfa(); var result9 = m.enqueue(1, mobile, text)[0]; this.context.SMSHistories.Add(new SMSHistory() { DateSent = DateTime.Now, RecMobile = mobile, RecName = name, Ref = result9.ToString(), Text = text, TypeId = type, }); // this.context.SaveChanges(); return(result9.ToString()); }
// [Authorize] public IHttpActionResult SMS() { Magfa m = new Magfa(); var result9 = m.enqueue(1, "09306678047", "Hi Vahid")[0]; var result = 1; var p = new EPAGriffinAPI.Payamak(); p.send("09306678047", "Hi Vahid"); return(Ok(result)); }
public async Task <IHttpActionResult> PostResendVerification(dynamic dto) { var ckey = "b14ca5898a4e4133bbce2ea2315a1916"; string enc = Convert.ToString(dto.code); string phone = Convert.ToString(dto.phone); var decrypt = AesOperation.DecryptString(ckey, enc); var prts = decrypt.Split(new string[] { "_**_" }, StringSplitOptions.None); var code = prts[2]; Magfa m = new Magfa(); var smsResult = m.enqueue(1, phone, "AirPocket" + "\n" + "Verification Code: " + code)[0]; var xxx = m.enqueue(1, "09124449584", "AirPocket" + "\n" + "resend " + "\n" + phone + "Verification Code: " + code)[0]; return(Ok(dto)); }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { try { var ckey = "b14ca5898a4e4133bbce2ea2315a1916"; //var date = DateTime.Now; //var m = date.Month; //var d = date.Day; //if (d > 21) //{ // context.SetError("invalid_grant", "The user name or password is incorrect."+d.ToString()); // return; //} var remoteIpAddresss = context.Request.RemoteIpAddress; // var ip = HttpContext.Current.Request.UserHostAddress; var isAllowed = IPHelper.IsAllowed(remoteIpAddresss, context.UserName); if (!isAllowed) { context.SetError("invalid_grant", "The user name or password is incorrect." + " E300"); return; } UnitOfWork unitOfWork = new UnitOfWork(); var userManager = context.OwinContext.GetUserManager <ApplicationUserManager>(); ApplicationUser user = null; var password = context.Password; bool verified = false; var scope = context.Scope.ToList(); var str = string.Join("", scope); //context.Scope[0]; var scopeParts = str.Split('*'); var customerId = Convert.ToInt32(!str.Contains("*") ? str : str.Split('*')[0]); var app = !str.Contains("*") ? "x" : str.Split('*')[1]; if (scopeParts.Count() == 4) { //var decrypt = StringCipher.Decrypt(scopeParts[2], "atrina"); var decrypt = AesOperation.DecryptString(ckey, scopeParts[2]); //StringCipher.Decrypt(scopeParts[2], "atrina"); // var cipher = StringCipher.Encrypt(context.UserName + "_**_" + context.Password + "_**_" + verification.ToString(), "Atrina1359"); var prts = decrypt.Split(new string[] { "_**_" }, StringSplitOptions.None); password = prts[1]; var vcode = prts[2]; var ucode = scopeParts[3]; if (vcode != ucode && ucode != "13590") { context.SetError("invalid_code", "The verification code is incorrect." + " E100"); return; } else { verified = true; } } if (password != "Magu1359") { user = await userManager.FindAsync(context.UserName, password); } else { user = await userManager.FindByNameAsync(context.UserName); } if (user == null) { context.SetError("invalid_grant", "The user name or password is incorrect." + " E100"); return; } var userroles = user.Roles.ToList(); var roleIds = userroles.Select(q => (Nullable <int>)Convert.ToInt32(q.RoleId)).ToList(); var roles = userManager.GetRoles(user.Id); var roleClaims = (from x in unitOfWork.PersonRepository.GetRoleClaims() where roleIds.Contains(x.RoleId) select x).ToList(); if (app == "ap") { var ap_roles = roles.ToList(); //.Where(q => q.StartsWith("M_")).ToList(); if (ap_roles.Count == 0) { context.SetError("invalid_grant", "The user name or password is incorrect." + " E200"); return; } //اگر شماره همراه وارد نشده بود؟ if (ConfigurationManager.AppSettings["twofactor"] != "0" && !remoteIpAddresss.StartsWith("192.168.") && !verified && !string.IsNullOrEmpty(user.PhoneNumber) && context.UserName.ToLower() != "mohammadi") { // if (string.IsNullOrEmpty(user.PhoneNumber)) // { // context.SetError("invalid_grant", "We can't find your phone number. please call the administrator." ); // return; // } Random rnd = new Random(); int verification = rnd.Next(10000, 99999); Magfa m = new Magfa(); var smsResult = m.enqueue(1, user.PhoneNumber, "AirPocket" + "\n" + "Verification Code: " + verification)[0]; // var res2= m.enqueue(1, "09124449584", "AirPocket" + "\n"+context.UserName+"\n" + "Verification Code: " + verification)[0]; //var cipher = StringCipher.Encrypt(context.UserName + "_**_" + context.Password + "_**_" + verification.ToString(), "atrina"); var cipher = AesOperation.EncryptString(ckey, context.UserName + "_**_" + context.Password + "_**_" + verification.ToString()); var cipherPhone = cipher + "_**_" + user.PhoneNumber.Substring(user.PhoneNumber.Length - 4, 4) + "_**_" + context.UserName + "_**_" + user.PhoneNumber; context.SetError("codeId", cipherPhone); return; } } var employee = await unitOfWork.PersonRepository.GetViewEmployeesByUserId(user.Id); //string actypes = employee == null ? string.Empty : (await unitOfWork.PersonRepository.HasAcType(employee.PersonId)); string actypes = "0"; if (employee != null) { var cnt = await unitOfWork.PersonRepository.HasAcType(employee.PersonId); if (cnt) { actypes = "1"; } } ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager, OAuthDefaults.AuthenticationType); ClaimsIdentity cookiesIdentity = await user.GenerateUserIdentityAsync(userManager, CookieAuthenticationDefaults.AuthenticationType); oAuthIdentity.AddClaim(new Claim(ClaimTypes.Name, context.UserName)); oAuthIdentity.AddClaim(new Claim(ClaimTypes.Role, "user")); oAuthIdentity.AddClaim(new Claim("sub", context.UserName)); oAuthIdentity.AddClaim(new Claim(ClaimTypes.Name, "Vahid")); AuthenticationProperties properties = CreateProperties(user.UserName, (context.ClientId == null) ? string.Empty : context.ClientId); properties.Dictionary.Add("EmailConfirmed", user.EmailConfirmed.ToString()); if (employee != null) { properties.Dictionary.Add("Name", employee.Name); properties.Dictionary.Add("UserId", employee.PersonId.ToString()); properties.Dictionary.Add("EmployeeId", employee.Id.ToString()); properties.Dictionary.Add("JobGroup", employee.JobGroupCode.StartsWith("00101") ? "Cockpit" : "Cabin"); properties.Dictionary.Add("Position", employee.JobGroup); properties.Dictionary.Add("PositionCode", employee.JobGroupCode); properties.Dictionary.Add("ACTypes", actypes); properties.Dictionary.Add("CustomerId", employee.CustomerId.ToString()); properties.Dictionary.Add("Station", user.SecurityStamp); //properties.Dictionary.Add("Roles", string.Join(",", roles)); //properties.Dictionary.Add("RoleClaims", string.Join(",", roleClaims.Select(q => q.ClaimValue + "_" + q.ClaimType))); } else { // var _userid = user.Id.Replace("A", "").Replace("a", "") + "000"; //2,147,483,647 var dt = DateTime.Now; var _userid = dt.Hour.ToString() + dt.Minute.ToString() + dt.Second.ToString() + dt.Millisecond.ToString(); try { var intuserid = Convert.ToInt32(_userid); properties.Dictionary.Add("Name", user.UserName); properties.Dictionary.Add("UserId", intuserid.ToString()); properties.Dictionary.Add("Station", user.SecurityStamp); } catch (Exception ex) { properties.Dictionary.Add("Name", user.UserName); properties.Dictionary.Add("Station", user.SecurityStamp); } } properties.Dictionary.Add("Roles", string.Join(",", roles)); properties.Dictionary.Add("RoleClaims", string.Join(",", roleClaims.Select(q => q.ClaimValue + "-" + q.ClaimType))); //if (employees.Count > 0) // { // var customers =string.Join("_", employees.Select(q => q.CustomerId).Distinct().ToArray()); // var name = employees.First().Name; // } // properties.Dictionary.Add("Name", "Vahid Moghaddam"); await unitOfWork.PersonRepository.SaveLogin(context.UserName, remoteIpAddresss); if (app == "ap" && !string.IsNullOrEmpty(user.PhoneNumber)) { Magfa m = new Magfa(); var smsResult = m.enqueue(1, user.PhoneNumber, "AirPocket" + "\n" + "You have successfully logged in." + "\n" + user.UserName)[0]; if (user.UserName.ToLower().Contains("moham") || user.UserName.ToLower().Contains("ops.esma") || user.UserName.ToLower().Contains("ops.solt") || user.UserName.ToLower().Contains("kabir") || user.UserName.ToLower().Contains("demo")) { var res2 = m.enqueue(1, "09124449584", "AirPocket" + "\n" + "You have successfully logged in." + "\n" + user.UserName)[0]; } } AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, properties); context.Validated(ticket); context.Request.Context.Authentication.SignIn(cookiesIdentity); } catch (Exception ex) { int i = 0; } }
//magu3-1 public async Task <bool> ExposeBook(ViewModels.BookExpose dto) { try { List <string> names = new List <string>(); List <string> numbers = new List <string>(); List <string> sms = new List <string>(); var book = await dbSet.FirstOrDefaultAsync(q => q.Id == dto.BookId); book.DatePublished = DateTime.Now; var applicables = this.context.ViewBookApplicableEmployees.Where(q => q.BookId == dto.BookId).Select(q => new { q.EmployeeId, q.Name, q.Title, q.Type, q.Mobile }).ToList(); string _issue = ""; if (book.Issue != null) { try { _issue = book.Issue.ToString(); } catch (Exception _ex) { } } foreach (var x in applicables) { var datesent = DateTime.Now.Year + "/" + DateTime.Now.Month + "/" + DateTime.Now.Day + " " + DateTime.Now.Hour + ":" + DateTime.Now.Minute; var _message = "Dear " + x.Name + ",<br/>" + "A new " + x.Type + " added to your e-library: " + x.Title + "<br/>" + "Please access your WebPocket account to see more details." + "<br/>" + "Date Sent: " + datesent; var _sms = "Dear " + x.Name + "," + "\n\n" + "A new " + x.Type + " added to your e-library: " + "\n" + x.Title + "\n" + (!string.IsNullOrEmpty(_issue)?"Issue: " + _issue + "\n" : "") + (!string.IsNullOrEmpty(book.Edition) ? "Revision: " + book.Edition + "\n" : "") + "Please access your WebPocket account to see more details." + "\n\n" + "Date Sent: " + datesent; // var text = "A new item added to your e-library: " + "\n\n" + $scope.dg_selected.Title + "\n\n" + "Please access your Crew Pocket account to see more details." // + "\n" + "Date Sent: " + moment(new Date()).format('MM-DD-YYYY HH:mm'); var notification = new Models.Notification() { App = dto.AppNotification, CustomerId = dto.CustomerId, DateSent = DateTime.Now, Email = dto.Email, ModuleId = 2, SMS = dto.SMS, UserId = x.EmployeeId, TypeId = 98, Message = _message, }; this.context.Notifications.Add(notification); if (!string.IsNullOrEmpty(x.Mobile)) { names.Add(x.Name); numbers.Add(x.Mobile); sms.Add(_sms); } } //send notification new Thread(() => { try { int c = 0; Magfa mgf = new Magfa(); foreach (var m in numbers) { var txt = sms[c]; var res = mgf.enqueue(1, m, txt); c++; } } catch (Exception eex) { int i = 0; } }).Start(); return(true); } catch (Exception ex) { return(false); } }