public ActionResult GroupCreate(string name, string description) { var n = new SMSGroup(); n.Name = name; n.Description = description; DbUtil.Db.SMSGroups.InsertOnSubmit(n); DbUtil.Db.SubmitChanges(); return(RedirectToAction("Index")); }
public ActionResult GroupCreate(string name, string description, bool systemFlag) { var group = new SMSGroup { Name = name, Description = description, SystemFlag = systemFlag, IsDeleted = false }; CurrentDatabase.SMSGroups.InsertOnSubmit(group); CurrentDatabase.SubmitChanges(); return(RedirectToAction("Index")); }
public void QuickSignInTest(bool useEmail) { var requestManager = FakeRequestManager.Create(); db = requestManager.CurrentDatabase; var membershipProvider = new MockCMSMembershipProvider { ValidUser = true }; var roleProvider = new MockCMSRoleProvider(); var build = "2020.2.1"; CMSMembershipProvider.SetCurrentProvider(membershipProvider); CMSRoleProvider.SetCurrentProvider(roleProvider); var person = CreatePerson(); person.CellPhone = RandomPhoneNumber(); person.EmailAddress = RandomEmailAddress(); db.SetSetting("UseMobileQuickSignInCodes", "true"); db.SetSetting("TwilioToken", RandomString()); db.SetSetting("TwilioSid", RandomString()); var group = db.SMSGroups.FirstOrDefault(g => g.SystemFlag == true); if (group == null) { group = new SMSGroup { SystemFlag = true, Name = "System Group", Description = "" }; db.SMSGroups.InsertOnSubmit(group); db.SubmitChanges(); } db.SMSNumbers.InsertOnSubmit(new SMSNumber { GroupID = group.Id, Number = RandomPhoneNumber(), LastUpdated = DateTime.Now }); db.SubmitChanges(); string messageBody = ""; if (useEmail) { db.SMTPClient = new MockEmailClient { Receive = (to, from, subject, body) => { messageBody = body; } }; } else { TwilioHelper.MockSender = (to, from, body, statusCallback) => { messageBody = body; return(new TwilioMessageResult { Status = "Sent" }); }; } var controller = new MobileAPIv2Controller(requestManager); var message = new MobileMessage { device = (int)MobileMessage.Device.ANDROID, instance = RandomString(), argString = useEmail ? person.EmailAddress : person.CellPhone, build = build, }; var data = message.ToString(); var result = controller.QuickSignIn(data) as MobileMessage; result.ShouldNotBeNull(); result.error.ShouldBe(0); messageBody.ShouldNotBeEmpty(); requestManager.CurrentHttpContext.Request.Headers["Authorization"] = "Quick " + FindCode(messageBody); message = new MobileMessage { device = (int)MobileMessage.Device.ANDROID, instance = message.instance, build = build, }; data = message.ToString(); result = controller.QuickSignInUsers(data) as MobileMessage; result.ShouldNotBeNull(); result.error.ShouldBe(0); result.count.ShouldBeGreaterThan(0); result.data.ShouldNotBeEmpty(); var list = JsonConvert.DeserializeObject <IEnumerable <MobileQuickSignInUser> >(result.data); var user = list.First(); user.userID.ShouldBe(0); user.peopleID.ShouldBe(person.PeopleId); user.name.ShouldBe(person.Name); user.user.ShouldBe("Create User"); var device = db.MobileAppDevices.SingleOrDefault(m => m.InstanceID == message.instance); device.ShouldNotBeNull(); device.AppVersion.ShouldBe(build); Should.Equals(device.DeviceTypeID, MobileMessage.Device.ANDROID); //Test QuickSignInCreateUser message = new MobileMessage { device = (int)MobileMessage.Device.ANDROID, instance = device.InstanceID, build = build, argInt = person.PeopleId, }; data = message.ToString(); result = controller.QuickSignInCreateUser(data) as MobileMessage; result.ShouldNotBeNull(); result.error.ShouldBe(0); result.count.ShouldBe(0); result.data.ShouldNotBeEmpty(); result.id.ShouldBeGreaterThan(0); var userId = result.id; var username = result.data; //Test SetDevicePIN var pin = "1234"; message = new MobileMessage { device = (int)MobileMessage.Device.ANDROID, instance = device.InstanceID, build = build, argInt = userId, argString = pin.Sha256Hash(), }; data = message.ToString(); result = controller.SetDevicePIN(data) as MobileMessage; result.ShouldNotBeNull(); result.error.ShouldBe(0); result.count.ShouldBe(0); result.data.ShouldNotBeEmpty(); //Test PIN authorization by getting the user's own profile requestManager.CurrentHttpContext.Request.Headers["Authorization"] = "PIN " + Convert.ToBase64String(Encoding.ASCII.GetBytes($"{username}:{pin.Sha256Hash()}")); message = new MobileMessage { device = (int)MobileMessage.Device.ANDROID, instance = device.InstanceID, build = build, argInt = person.PeopleId, }; data = message.ToString(); result = controller.FetchPerson(data) as MobileMessage; result.ShouldNotBeNull(); result.error.ShouldBe(0); result.count.ShouldBe(1); result.data.ShouldNotBeEmpty(); }