Git Repository Public Repository

CPE_learningsite

URLs

Copy to Clipboard

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mvc;
using System.Xml;
using CPE.App.Web.Code;
using CPE.App.Web.Connect;
using CPE.App.Web.Helpers;
using CPE.App.Web.Models;

namespace CPE.App.Web.Controllers {
    public class IndexController : BaseController {
        public enum MeetingType {
            Adobe,
            Elucidat
        }

        private bool IsLocal() {
            var address = Request.UserHostAddress;
            if (address.StartsWith("192.") || address.StartsWith("10.211") || address == "::1")
                return true;
            return false;
        }

        private bool IsAdmin(string login, string password)
        {
            return Database.Users.Any(t => t.IsAdmin && t.Login == login && t.Password == password);
        }

        private bool IsAdmin(string password)
        {
            return Database.Users.Any(t => t.IsAdmin && t.Password == password);
        }

        // GET: Index
        [HttpGet]
        public ActionResult Index(int? year) {
            if(Request.Cookies["allowed"] == null && !IsLocal())
                return Redirect("http://www.cpeonline.com/webcasts");

            //string systemPassword = ConfigurationManager.AppSettings["password"];
            if (Request.Cookies["allowed"] != null && !IsAdmin(Request.Cookies["allowed"].Value))
            {
                return Redirect("http://www.cpeonline.com/webcasts");
            }

            DateTime now = DateTime.UtcNow;

            if(!year.HasValue) {
                year = DateTime.Now.Year;
            }

            List<MeetingSessionsDataResult> meetingSessions = Database.MeetingSessionsData()
                                                                      .Where(msd => msd.EndDate.HasValue && msd.EndDate <= now && (msd.StartDate >= new DateTime(year.Value, 1, 1) && msd.StartDate < new DateTime(year.Value + 1, 1, 1)))
                                                                      .OrderByDescending(msd => msd.StartDate)
                                                                      .ToList();
            return View(meetingSessions);
        }

        [HttpGet]
        public ActionResult SessionDetails(int meetingSessionKey) {
            Extensions.LogServiceCall("[IndexController][SessionDetails]", string.Format("Beginning: meetingSessionKey = {0}", meetingSessionKey));

            var meetingSession = Database.MeetingSessions.Single(ms => ms.MeetingSessionKey == meetingSessionKey);
            var result = new AdobeSessionViewModel {
                MeetingSession = meetingSession,
                ParticipantSessionsDataResult = Database.ParticipantSessionsData(meetingSessionKey)
                                                        .ToList(),
                GetSessionReportResult = Database.GetSessionReport(meetingSessionKey)
                                                 .ToList(),
                WebcastPurchaseDataResult = Database.WebcastPurchaseData(meetingSession.SCO_ID, meetingSessionKey)
                                                    //.Where(w => w.Sco == meetingSession.SCO_ID && w.mDate.DayOfYear >= meetingSession.StartDate.DayOfYear)
                                                    .ToList()
            };
            //if (result.ParticipantSessionsDataResult.Count == 0) {
            adobe.GetAdobeTransactions(meetingSession, Database);
            Database.SubmitChanges();

            result = new AdobeSessionViewModel {
                MeetingSession = meetingSession,
                ParticipantSessionsDataResult = Database.ParticipantSessionsData(meetingSessionKey)
                                                        .ToList(),
                GetSessionReportResult = Database.GetSessionReport(meetingSessionKey)
                                                 .ToList(),
                WebcastPurchaseDataResult = Database.WebcastPurchaseData(meetingSession.SCO_ID, meetingSessionKey)
                                                    .ToList()
            };
            //}
            return View(result);
        }

        [HttpGet]
        public ActionResult RetrieveSession(int meetingSessionKey) {
            Extensions.LogServiceCall("[IndexController][RetrieveSession]", string.Format("Beginning: meetingSessionKey = {0}", meetingSessionKey));

            var meetingSession = Database.MeetingSessions.Single(ms => ms.MeetingSessionKey == meetingSessionKey);
            if(Database.ParticipantSessionsData(meetingSessionKey)
                       .ToList()
                       .Count == 0) {
                adobe.GetAdobeTransactions(meetingSession, Database);
                Database.SubmitChanges();
            }

            return RedirectToAction("SessionDetails", new {meetingSessionKey});
        }


        [HttpGet]
        public ActionResult TestElucidat()
        {
            var baseUrl = "https://api-launchpad.elucidat.com/";
            var urlFull = "health/ping";
            Extensions.LogServiceCall("[IndexController][TestElucidat]", $"Beginning: {baseUrl}{urlFull}");

            ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Ssl3;
            ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Tls;
            ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Tls11;
            // Add TLS 1.2
            ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12;

            var client = new WebClient { BaseAddress = baseUrl };
            client.Headers.Clear();
            client.Headers["Accept"] = "application/json";
            var response = client.DownloadString(urlFull);
            Extensions.LogServiceCall("[IndexController][TestElucidat]", $"Response: {response}");


            return Content(response);
        }

        [HttpGet]
        public ActionResult Login(string meetingUrl, string d = null, string c = null) {
            meetingUrl = meetingUrl?.Trim();
            d = d?.Trim();
            c = c?.Trim();


            Extensions.LogServiceCall("[IndexController][Login|Get]", string.Format("meetingUrl = {0} d (PurchaseDate) = {1} c (TicketFromUrl) = {2}", meetingUrl, d, c));

            //Webcast and Rebroadcast access test course
            if(meetingUrl.ToLower() == "test_room") {
                var baseUrl = ConfigurationManager.AppSettings["Connect.Url"];
                var testUrl = ConfigurationManager.AppSettings["Connect.AccessTestMeetingUrl"];
                var accessTestUrl = baseUrl + '/' + testUrl;
                return Redirect(accessTestUrl);
            }
            var meetingType = meetingUrl.Contains('-') ? MeetingType.Elucidat : MeetingType.Adobe;

            if(meetingType == MeetingType.Elucidat) {
                var releaseCode = meetingUrl.Substring(meetingUrl.IndexOf('-') + 1);
                Extensions.LogServiceCall("[IndexController][Login|Get]", string.Format("meetingUrl = {0} releaseCode = {1}", meetingUrl, releaseCode));

                ReleaseModel release = ElucidatMeetingConnection.GetReleaseDetails(releaseCode);
                string projectName = null;
                if(release != null && release.Project != null) {
                    projectName = release.Project.Name;
                }
                return View("elucidatlogin", new ElucidatCourseView {Name = projectName, Url = meetingUrl, PurchaseDate = d, TicketFromUrl = c, Message = null});
            }
            //if (ConfigurationManager.AppSettings["CPE.AdobeTicketingOn"].ToLower() == "true")
            //{
            //    //The flag is unnecessary now since we're keeping magic passcode access available. Non-ticketed link is now magicTicket 

            // }

            XmlDocument meeting = AdobeMeetingConnection.getAdobeMeeting(meetingUrl);
            if(meeting != null) {
                if(meeting.SelectSingleNode("//sco")
                          .Attributes["icon"].Value != "archive") {
                    return View("login", new AdobeMeetingView {
                        Name = meeting.SelectSingleNode("//sco/name")
                                      .InnerText,
                        HasPassCode = meeting.SelectSingleNode("//meeting-passcode") != null,
                        PurchaseDate = d,
                        TicketFromUrl = c
                    });
                }
            }
            return null;
        }

        [HttpPost]
        public ActionResult Login(string meetingUrl, string firstname, string lastname, string email, string passcode,
                                  string courseName, string ticket = null, string ticketFromUrl = null, string purchaseDate = null,
                                  string message = null) {
            meetingUrl = meetingUrl?.Trim();
            firstname = firstname?.Trim();
            lastname = lastname?.Trim();
            email = email?.Trim();
            passcode = passcode?.Trim();
            courseName = courseName?.Trim();
            ticket = ticket?.Trim();
            ticketFromUrl = ticketFromUrl?.Trim();
            purchaseDate = purchaseDate?.Trim();
            message = message?.Trim();

            Extensions.LogServiceCall("[IndexController][Login|Post]", string.Format("email = {0} meetingUrl = {1} ticket = {2} ticketFromUrl = {3} purchaseDate = {4} firstname = {5} lastname = {6} passcode = {7} courseName = {8}", email, meetingUrl, ticket, ticketFromUrl, purchaseDate, firstname, lastname, passcode, courseName));

            var magicTicketLogin = string.IsNullOrEmpty(ticketFromUrl);
            var meetingType = meetingUrl.Contains('-') ? MeetingType.Elucidat : MeetingType.Adobe;

            if(meetingType.Equals(MeetingType.Elucidat)) {
                var releaseCode = meetingUrl.Substring(meetingUrl.IndexOf('-') + 1);

                if(!ticket.Equals(ticketFromUrl) ||
                   !VerifyAccess.VerifyTicket(ticket, meetingUrl, firstname, lastname, email, purchaseDate)) {
                    return View("elucidatlogin", new ElucidatCourseView {
                        Url = meetingUrl,
                        Name = courseName,
                        PurchaseDate = purchaseDate,
                        TicketFromUrl = ticketFromUrl,
                        Message =
                            "Invalid Login. Please re-enter your information. This information MUST match the information in the email you received with your passcode. If you continue to have trouble, please contact Customer Service at 1-800-544-1114 or email us at sswebcast@cpeincmail.com"
                    }
                        );
                }

                PurchasedCourse course =
                    Database.PurchasedCourses.SingleOrDefault(pc => pc.Ticket == ticket && pc.ContentUrl == meetingUrl);

                if(course == null) {
                    //no purchase record yet, look for release details in database
                    CourseDetail release = Database.CourseDetails.SingleOrDefault(r => r.ReleaseCode == releaseCode);
                    if(release == null) {
                        //course isn't in db yet, get details form api
                        ReleaseModel releaseCourse = ElucidatMeetingConnection.GetReleaseDetails(releaseCode);
                        var done = ReleaseHelper.GetReleaseDescriptionDetails(releaseCourse);
                        if(done) {
                            release = Database.CourseDetails.SingleOrDefault(cd => cd.ReleaseCode == releaseCode);
                        }
                    }
                    string formattedPdate = purchaseDate.Substring(0, 4) + '-' + purchaseDate.Substring(4, 2) + '-' +
                                            purchaseDate.Substring(6, 2);
                    DateTime pDate = Convert.ToDateTime(formattedPdate);
                    course = new PurchasedCourse {
                        ContentUrl = meetingUrl,
                        CourseName = release.Name,
                        FirstName = firstname,
                        LastName = lastname,
                        Email = email,
                        Ticket = ticket,
                        PurchaseDate = pDate,
                        Presenter = release.Presenter,
                        Fos = release.Fos,
                        Credits = release.Credits,
                        CertificateDate = null,
                        FailedAttempts = 0,
                        isManualCertificate = false
                    };
                    Database.PurchasedCourses.InsertOnSubmit(course);
                }

                Database.SubmitChanges();

                //verify access (PurchaseDate<1yrold) and access not revoked
                if(!VerifyAccess.AccessBlocked(course) && VerifyAccess.IsValid(course)) {
                    string courseUrl = ElucidatMeetingConnection.GetLaunchLink(releaseCode, firstname, lastname, email);

                    Regex linkParser = new Regex(@"\b(?:https?://)\S+\b",
                                                 RegexOptions.Compiled | RegexOptions.IgnoreCase);
                    string rawString = courseUrl;
                    string goodUrl = linkParser.Match(rawString)
                                               .Value;

                    return Redirect(goodUrl);
                }

                //Access is expired or Revoked
                return View("elucidatlogin", new ElucidatCourseView {
                    Url = meetingUrl,
                    Name = courseName,
                    PurchaseDate = purchaseDate,
                    TicketFromUrl = ticketFromUrl,
                    Message =
                        "Access to this course is no longer available. Please contact Customer Service at 1-800-544-1114 or email us at sswebcast@cpeincmail.com"
                }
                    );
            }
            if((ConfigurationManager.AppSettings["CPE.AdobeTicketingOn"].ToLower() == "true") & !magicTicketLogin) {
                if(passcode == null) {
                    passcode = (DateTime.UtcNow.ToString("MMM") + DateTime.UtcNow.Day.ToString("00")).ToLower();
                }
                if(!ticketFromUrl.Equals(ticket)) {
                    return RedirectToAction("Login");
                }
                if(!VerifyAccess.VerifyTicket(ticket, meetingUrl, firstname, lastname, email, purchaseDate)) {
                    return RedirectToAction("Login");
                }

                //if valid continue on to existing way of doing things
            }

            string connectUrl = ConfigurationManager.AppSettings["Connect.Url"];
            int accountId = int.Parse(ConfigurationManager.AppSettings["Connect.AccountId"]);
            string password = Guid.NewGuid()
                                  .ToString()
                                  .Replace("{", "")
                                  .Replace("}", "")
                                  .Substring(0, 8);
            Session admin = AdobeMeetingConnection.GetAdobeAdminSession();
            var request = new Request(admin, "principal-list");
            request.Parameters.Add("filter-type", "guest");
            request.Parameters.Add("filter-type", "user");
            request.Parameters.Add("filter-login", email);
            if(request.Execute() && request.Status == Status.OK) {
                Extensions.LogServiceCall("[IndexController][Login|Post]", string.Format("email = [{0}] request.XmlResults.InnerXml = {1}", email, request.XmlResults.InnerXml));

                int principalId;
                if(request.XmlResults.SelectSingleNode("//principal") == null) {
                    principalId = Connect.Login.CreateGuest(admin, email, password, email, firstname, lastname);
                } else {
                    principalId = int.Parse(request.XmlResults.SelectSingleNode("//principal")
                                                   .Attributes["principal-id"].Value);
                    email = request.XmlResults.SelectSingleNode("//principal/login")
                                   .InnerText;
                    if(request.XmlResults.SelectSingleNode("//principal")
                              .Attributes["type"].Value == "user")
                        return RedirectToAction("Login");
                }
                if(principalId < 1)
                    return RedirectToAction("Login");


                Connect.Login.ResetPassword(admin, principalId, password);
                Session session = Connect.Login.UserLogin(email, password, connectUrl, accountId);

                var meetingView = new AdobeMeetingView {
                    Name = AdobeMeetingConnection.getAdobeMeetingName(meetingUrl),
                    PrincipalId = principalId,
                    Url =
                        string.Format("{0}/{1}?session={2}&launcher=false", connectUrl, meetingUrl,
                                      session.SessionKey) + (passcode == null
                                                                 ? ""
                                                                 : "&meeting-passcode=" + passcode)
                };


                Participant participant = Database.Participants.SingleOrDefault(p => p.Principal_ID == principalId);
                if(participant == null) {
                    participant = new Participant {
                        Principal_ID = principalId,
                        FirstName = firstname,
                        LastName = lastname,
                        Email = email
                    };
                    Database.Participants.InsertOnSubmit(participant);
                }

                Database.SubmitChanges();

                var certificateId = 0;
                int scoId = AdobeMeetingConnection.getAdobeMeetingSco(meetingUrl);

                if(!magicTicketLogin) {
                    string formattedPdate = purchaseDate.Substring(0, 4) + '-' +
                                            purchaseDate.Substring(4, 2) +
                                            '-' + purchaseDate.Substring(6, 2);
                    DateTime pDate = Convert.ToDateTime(formattedPdate);

                    ParticipantPurchase purchase =
                        Database.ParticipantPurchases.SingleOrDefault(
                                                                      p =>
                                                                      p.PrincipalID == principalId & p.Ticket == ticketFromUrl &
                                                                      p.MeetingSco == scoId);
                    if(purchase == null) {
                        purchase = new ParticipantPurchase {
                            FirstName = firstname,
                            LastName = lastname,
                            Email = email,
                            PrincipalID = principalId,
                            MeetingName = meetingView.Name,
                            MeetingDate = DateTime.UtcNow,
                            MeetingSco = scoId,
                            Ticket = ticketFromUrl,
                            PurchaseDate = pDate,
                            EarnedCertificate = false,
                            Credits = 0
                        };
                        Database.ParticipantPurchases.InsertOnSubmit(purchase);

                        Extensions.LogServiceCall("[IndexController][Login|Post]", string.Format("email = {0} scoId = {1} principalId = {2} MeetingDate = {3}", email, scoId, principalId, purchase.MeetingDate));
                    }

                    Database.SubmitChanges();
                    certificateId = purchase.Purchase_ID;
                }
                meetingView.CertificateId = certificateId;
                meetingView.ScoId = scoId;

                Extensions.LogServiceCall("[IndexController][Login|Post]", string.Format("email = {0} scoId = {1} certificateId = {2} principalId = {3}", email, scoId, certificateId, principalId));

                var idCookie = new HttpCookie("id") {
                    Value = principalId.ToString(),
                    Expires = DateTime.UtcNow.AddDays(1)
                };
                Response.Cookies.Add(idCookie);


                request = new Request(admin, "principal-update");
                request.Parameters.Add("first-name", firstname);
                request.Parameters.Add("last-name", lastname);
                request.Parameters.Add("principal-id", principalId.ToString());
                request.Execute();

                return View("meeting", meetingView);
            }
            return RedirectToAction("Login");
        }

        [HttpGet]
        public ActionResult Admin() {
            return View();
        }

        public ActionResult Email() {
            var email = new MailMessage {
                To = {
                    "sophia@sophicsystems.com"
                },
                Subject = "[CPE] Email Test",
                Body = "Email test has been received.",
                From = new MailAddress("support@intesolv.com")
            };
            var server = new SmtpClient("localhost");
            server.Send(email);

            return Redirect("/");
        }
        public ActionResult SendCerificateEmail(string email, string url, string key)
        {
            if (key != "q1w2e3") return Content("Bad key");
            var course = Database.PurchasedCourses
                .Where(c => c.Email == email && c.ContentUrl == url)
                .OrderByDescending(c => c.CertificateDate).FirstOrDefault();

            var done = SendEmailHelperWeb.SendCertificateEmail(course);

            var s = url.Split('-');
            var courseName = Database.CourseDetails
                .FirstOrDefault(c => c.ReleaseCode == s[1])?.Name;

            Utilities.LogWrapper.Info("[TinCanHelper][HandleStatement] {0} cert sent email={1} courseName={2}", DateTime.UtcNow.ToString("yyyyMMdd_HHmmss"), email, courseName);

            return Content("Certificate send successfully");
        }

        [HttpPost]
        public ActionResult Admin(string login, string passcode) {
            login = login?.Trim();
            passcode = passcode?.Trim();

           // string systemPassword = ConfigurationManager.AppSettings["password"];
            if(IsAdmin(login, passcode)) {
                var reportingCookie = new HttpCookie("allowed") {
                    Value = passcode,
                    Expires = DateTime.UtcNow.AddDays(1)
                };
                Response.Cookies.Add(reportingCookie);
            }
            return Redirect("/");
        }

        [HttpGet]
        public ActionResult CourseDetails(string releaseCode) {
            releaseCode = releaseCode?.Trim();

            var course = Database.CourseDetails.Single(cd => cd.ReleaseCode == releaseCode);
            var result = new ElucidatCourseViewModel {
                CourseDetail = course,
                PurchasedCoursesDataResult = Database.PurchasedCoursesData(releaseCode)
                                                     .OrderByDescending(pc => pc.PurchaseDate)
                                                     .ToList()
            };

            return View(result);
        }

        [HttpGet]
        public ActionResult Elucidat() {
            if(Request.Cookies["allowed"] == null && !IsLocal())
                return Redirect("http://www.cpeonline.com/webcasts");
//            string systemPassword = ConfigurationManager.AppSettings["password"];
            if(Request.Cookies["allowed"] != null && (!IsAdmin(Request.Cookies["allowed"].Value)))
                return Redirect("http://www.cpeonline.com/webcasts");
            DateTime now = DateTime.UtcNow;

            List<CourseListingsDataResult> courseListings = Database.CourseListingsData()
                                                                    .Where(cl => cl.CreatedDate != null)
                                                                    .OrderBy(cl => cl.Name)
                                                                    .ToList();
            return View(courseListings);
        }

        [HttpGet]
        public ActionResult Wufoo(int id) {
            //https://cpeonline.wufoo.com/forms/cpe-webcast-evaluation/def/Field1=Jason&Field2=Wigginton&Field3-1=7&Field3-2=2&Field3=2012&Field4=1234&Field5=J.%20McIntosh&Field6=ConnectPro&Field7=Test101&Field8=Test%20topic
            ParticipantTracking pt = Database.ParticipantTrackings.OrderByDescending(p => p.StartDate)
                                             .FirstOrDefault(p => p.Principal_ID == id);
            string url = ConfigurationManager.AppSettings["Wufoo.Survey1.1"];
            if(pt == null) {
                Extensions.LogServiceCall("[IndexController][Wufoo]", string.Format("id = {0} url = {1}", id, url));
                return Redirect(url);
            }

            MeetingDetail d = pt.MeetingParticipantSession.MeetingSession.Meeting.MeetingDetail;
            DateTime date = Extensions.GetLocalDateTime(DateTime.UtcNow);
            url += string.Format(ConfigurationManager.AppSettings["Wufoo.Survey1.2"], pt.Participant.FirstName, pt.Participant.LastName, date.Month.ToString("00"), date.Day.ToString("00"), date.Year, d.TopicID, d.TopicName, d.Instructor, d.Location, d.CourseCode);
            Extensions.LogServiceCall("[IndexController][Wufoo]", string.Format("id = {0} url = {1}", id, url));
            return Redirect(url);
        }

        public ActionResult Survey() {
            int id = 0;
            string url = ConfigurationManager.AppSettings["Wufoo.Survey1.1"];
            string cookie = Request.Cookies["id"] == null
                                ? "0"
                                : Request.Cookies["id"].Value;
            int.TryParse(cookie, out id);
            if(id == 0) {
                return Redirect(url);
            }
            Extensions.LogServiceCall("[IndexController][Survey]", string.Format("id = {0}", id));
            ParticipantTracking pt = Database.ParticipantTrackings.OrderByDescending(p => p.StartDate)
                                             .FirstOrDefault(p => p.Principal_ID == id);
            if(pt == null)
                return Redirect(url);

            MeetingDetail d = pt.MeetingParticipantSession.MeetingSession.Meeting.MeetingDetail;
            DateTime date = Extensions.GetLocalDateTime(DateTime.UtcNow);
            url += string.Format(ConfigurationManager.AppSettings["Wufoo.Survey1.2"], pt.Participant.FirstName, pt.Participant.LastName, date.Month.ToString("00"), date.Day.ToString("00"), date.Year, d.TopicID, d.TopicName, d.Instructor, d.Location, d.CourseCode);
            return Redirect(url);
        }

        [HttpGet]
        public ActionResult AllowReporting(Guid? id) {
            //if (id.HasValue && id == Guid.Parse("")) {
            //    var reportingCookie = new HttpCookie("reporting") {Value = "1", Expires = DateTime.MaxValue};
            //    Response.Cookies.Add(reportingCookie);
            //    return Redirect("/");
            //}
            //return Redirect("http://www.cpeonline.com/webcasts");
            return RedirectToAction("Admin");
        }

        [HttpGet]
        public ActionResult GetTicket(string courseUrl) {
            courseUrl = courseUrl?.Trim();

            TicketModel ticketInfo = new TicketModel {
                CourseUrl = courseUrl
            };
            //return the view as a partial view that opens in a pretty jquery ui form (dialog) within the page, not a new page
            return PartialView(ticketInfo);
        }

        [HttpPost]
        public string GetTicket(string firstname, string lastname, string email, string contenturl) {
            //NOT IMPLEMENTED. possible solution to "magic ticket" request for ondemand course, since a global entry would not make sense
            //generate hashed ticket link for a specific user for an ondemand course. This will bypass cpe's commerce site and allow cpe customer service to generate an access link

            firstname = firstname?.Trim();
            lastname = lastname?.Trim();
            email = email?.Trim();
            contenturl = contenturl?.Trim();

            string purchasedate = DateTime.Now.ToString("yyyyMMdd");
            var ticket = VerifyAccess.generateTicket(contenturl, firstname, lastname, email, purchasedate);

            var link = "http://cpeonlineselfstudywebcasts.com/" + contenturl + "?d=" + purchasedate + "&c=" + ticket;
            return link;
        }

        // GET: CertificateReport
        [HttpGet]
        public ActionResult CertificateReport() {
            List<CertficateDataResult> earnedCertificates = Database.CertficateData()
                                                                    .OrderBy(ec => ec.Course)
                                                                    .ToList();
            return View(earnedCertificates);
        }

        public ActionResult WebcastCertificateReport() {
            List<WebcastCertficateDataResult> earnedCertificates = Database.WebcastCertficateData()
                                                                           .OrderBy(ec => ec.MeetingName)
                                                                           .ToList();
            return View(earnedCertificates);
        }

        //public string SendCert(int meeting_sco, int certificate_id, int principal_id)
        //{
        //    //TODO (webcast) make outcome dictionary to return pass, fail, ineligible, or wonky:contact cust serv
        //    string _fail = "fail";
        //    if (certificate_id > 0)
        //    {
        //        ParticipantPurchase purchase =
        //            Database.ParticipantPurchases.FirstOrDefault(p => p.Purchase_ID == certificate_id && p.PrincipalID == principal_id);

        //        if (purchase == null)
        //        {
        //            //if the certificate_id is >0 then purchase would only be null because of record being deleted while user was in the meeting, or the principalID got mis-matched
        //            return _fail; // TODO probably return wonky, contact cust service message
        //        }

        //        if (!purchase.EarnedCertificate)
        //        {
        //            var meeting = Database.MeetingSessions.FirstOrDefault(
        //                    m =>
        //                        m.Recording == false && m.SCO_ID == meeting_sco &&
        //                        m.StartDate.DayOfYear == DateTime.UtcNow.DayOfYear);
        //            if (meeting == null)
        //            {
        //                return _fail;//TODO return wonky
        //            }

        //            int meetingSessionKey = meeting.MeetingSessionKey;

        //            MeetingParticipantSession meetingParticipantSession =
        //                Database.MeetingParticipantSessions.FirstOrDefault(
        //                    m => m.MeetingSessionKey == meetingSessionKey && m.ParticipantKey == principal_id);
        //            if (meetingParticipantSession == null)
        //            {
        //                return _fail;//TODO return wonky
        //            }

        //            List<ParticipantSessionsDataResult> participantSessionsDataResult =
        //                Database.ParticipantSessionsData(meetingSessionKey)
        //                    .ToList();

        //            var participantSessionsData =
        //                participantSessionsDataResult.OrderBy(p => p.MeetingParticipantSessionKey)
        //                    .FirstOrDefault(
        //                        p =>
        //                            p.MeetingParticipantSessionKey ==
        //                            meetingParticipantSession.MeetingParticipantSessionKey);

        //            if (participantSessionsData == null)
        //            {
        //                return _fail;//TODO is this a return wonky? it means they weren't tracked
        //            }

        //            MeetingSessionsDataResult meetingSession = Database.MeetingSessionsData().FirstOrDefault(m => m.MeetingSessionKey == meetingSessionKey);
        //            if (meetingSession == null)
        //            {
        //                return _fail;//TODO return wonky
        //            }

        //            var courseLength = meetingSession.ActualSessionTime.GetValueOrDefault(); //in minutes
        //            double courseCredits = courseLength / 50.0; //1 credit per 50 minutes
        //            List<double> maxCourseCredits = ConfigurationManager.AppSettings["MaxCourseCreditList"].Split(';').Select(s => double.Parse(s)).ToList(); //max credits cut list
        //            int mx = maxCourseCredits.BinarySearch(courseCredits); //find appropriate max for this course
        //            double maxCredits = maxCourseCredits[mx >= 0 ? mx : ~mx - 1];//...by rounding down
        //            double realCredits = participantSessionsData.SessionCredit == null ? 0 : (double)participantSessionsData.SessionCredit.Value; //users credits per adobe
        //            purchase.Credits = Math.Min(maxCredits, realCredits); //user awarded no more than max possible credits for the course

        //            MeetingDetail meetingDetail =
        //                Database.MeetingDetails.FirstOrDefault(m => m.MeetingKey == purchase.MeetingSco);

        //            purchase.Presenter = meetingDetail == null ? "" : meetingDetail.Instructor;

        //            double percentComplete = (participantSessionsData.SessionEngagementCount.GetValueOrDefault() == 0 ? 
        //                    1 : (participantSessionsData.SessionHeartbeatCount.GetValueOrDefault() / participantSessionsData.SessionEngagementCount.Value));

        //            if (percentComplete >= .75) //threshold for earning a certificate is 75% response rate
        //            {
        //                purchase.EarnedCertificate = true;
        //            }

        //            Database.SubmitChanges();

        //            if (purchase.EarnedCertificate)
        //            {
        //                //TODO with return Pass dictionary value as string.format with replace of certUrl
        //                //string certUrl = AdobeCertificateHelper.SendWebcastCert(purchase);
        //                //format the outcome.pass.value message with certUrl replace
        //                //return outcome.pass with its value
        //                return AdobeCertificateHelper.SendWebcastCert(purchase);
        //            }
        //            //TODO return outcome.fail
        //            return AdobeCertificateHelper.SendFailNotice(purchase);
        //        }
        //    }
        //    return _fail;// TODO return ineligible.need to make AdobeCertificateHelper.SendIneligibleNotice(principalId)
        //}

        //public participantResult ProcessParticipantResult(participantResult result, ParticipantPurchase purchase)
        //{
        //    if (purchase == null)
        //    {
        //        result = participantResult.Ineligible;
        //    }
        //    switch (result)
        //    {
        //        case participantResult.Ineligible:
        //            //Ineligible for auto-cert; not sending notice.  
        //            break;
        //        case participantResult.Fail:
        //            AdobeCertificateHelper.SendFailNotice(purchase);
        //            break;
        //        case participantResult.Pass:
        //            AdobeCertificateHelper.SendWebcastCert(purchase);
        //            //Send Cert email;
        //            break;
        //        case participantResult.Wonky:
        //            //something went wrong: send email to contact cust service? send email to cpe? do nothing? 
        //            break;
        //    }
        //    return result;
        //}

        //public ActionResult BatchProcessParticipantResults(int msk)
        //{
        //    List<ParticipantSessionsDataResult> psdr = BaseController.Database.ParticipantSessionsData(msk).ToList();
        //    var meeting = BaseController.Database.MeetingSessions.FirstOrDefault(m => m.MeetingSessionKey == msk);
        //    if (meeting == null)
        //    {
        //        return Content("Error retrieving meeting session details.");
        //    }
        //    var scoId = meeting.SCO_ID;

        //    foreach (var p in psdr)
        //    {
        //        ParticipantPurchase purchase = null;
        //        participantResult result = participantResult.Wonky;
        //        var mpsk = p.MeetingParticipantSessionKey;
        //        var meetingParticipantSession =
        //            BaseController.Database.MeetingParticipantSessions.FirstOrDefault(
        //                mps => mps.MeetingParticipantSessionKey == mpsk && mps.MeetingSessionKey == msk);

        //        if (meetingParticipantSession != null)
        //        {
        //            var principalId = meetingParticipantSession.ParticipantKey;

        //            purchase = BaseController.Database.ParticipantPurchases.FirstOrDefault(pp => pp.PrincipalID == principalId && pp.MeetingSco == scoId);
        //            if (purchase == null)
        //            {
        //                result = participantResult.Ineligible;
        //            }
        //            else
        //            {
        //                MeetingSessionsDataResult meetingSession = Database.MeetingSessionsData().FirstOrDefault(m => m.MeetingSessionKey == msk);
        //                if (meetingSession != null)
        //                {
        //                    var courseLength = meetingSession.ActualSessionTime.GetValueOrDefault(); //in minutes
        //                    double courseCredits = courseLength/50.0; //1 credit per 50 minutes
        //                    List<double> maxCourseCredits =
        //                        ConfigurationManager.AppSettings["MaxCourseCreditList"].Split(';')
        //                            .Select(s => double.Parse(s))
        //                            .ToList(); //max credits cut list
        //                    int mx = maxCourseCredits.BinarySearch(courseCredits);
        //                        //find appropriate max for this course
        //                    double maxCredits = maxCourseCredits[mx >= 0 ? mx : ~mx - 1]; //...by rounding down
        //                    double realCredits = p.SessionCredit == null
        //                        ? 0
        //                        : (double) p.SessionCredit.Value; //users credits
        //                    purchase.Credits = Math.Min(maxCredits, realCredits);
        //                        //user awarded no more than max possible credits for the course

        //                    MeetingDetail meetingDetail =
        //                        Database.MeetingDetails.FirstOrDefault(m => m.MeetingKey == purchase.MeetingSco);

        //                    purchase.Presenter = meetingDetail == null ? "" : meetingDetail.Instructor;

        //                    double percentComplete =
        //                        (p.SessionEngagementCount.GetValueOrDefault() == 0
        //                            ? 1
        //                            : (p.SessionHeartbeatCount.GetValueOrDefault()/
        //                               p.SessionEngagementCount.Value));

        //                    if (percentComplete >= .75) //threshold for earning a certificate is 75% response rate
        //                    {
        //                        purchase.EarnedCertificate = true;
        //                        result = participantResult.Pass;
        //                    }
        //                    else
        //                    {
        //                        result = participantResult.Fail;
        //                    }

        //                    Database.SubmitChanges();
        //                }
        //            }
        //        }
        //        ProcessParticipantResult(result, purchase);
        //    }
        //    return Content("done");
        //}

        public ActionResult Result(int principalid, int scoid) {
            var resultView = new SessionResultViewModel();
            participantResult result = participantResult.Wonky;

            Extensions.LogServiceCall("[IndexController][Result]", string.Format("Beginning: principalid = {0} scoid = {1}", principalid, scoid));

            Extensions.LogServiceCall("[IndexController][Result]", string.Format(
                                                                                 "principalid = {0} scoid = {1} DateTime.UtcNow.DayOfYear = {2} DateTime.Now.DayOfYear = {3}",
                                                                                 principalid, scoid, DateTime.UtcNow.DayOfYear, DateTime.Now.DayOfYear));

            var meeting =
                Database.MeetingSessions.FirstOrDefault(
                                                        m => m.SCO_ID == scoid && m.StartDate.DayOfYear == DateTime.UtcNow.DayOfYear);
            if(meeting != null) {
                int msk = meeting.MeetingSessionKey;
                MeetingParticipantSession meetingParticipantSession =
                    Database.MeetingParticipantSessions.FirstOrDefault(
                                                                       m => m.MeetingSessionKey == msk && m.ParticipantKey == principalid);
                if(meetingParticipantSession != null) {
                    adobe.GetAdobeTransactions(meetingParticipantSession.MeetingSession, Database);
                    Database.SubmitChanges();

                    result = SessionEnd.ProcessEndOfMeetingSessionHeartbeatResultsForParticipant(Database, meetingParticipantSession);
                    switch (result) {
                        case participantResult.Ineligible:
                            resultView.Message = Utilities.Result.RenderIneligibleResult(principalid);
                            break;
                        case participantResult.Fail:
                            resultView.Message = Utilities.Result.RenderFailResult(principalid);
                            break;
                        case participantResult.Pass:
                            resultView.Message = Utilities.Result.RenderPassResult(principalid);
                            break;
                        case participantResult.Wonky:
                            resultView.Message = Utilities.Result.RenderWonkyResult();
                            break;
                    }
                } else {
                    Extensions.LogServiceCall("[IndexController][Result]", string.Format(
                                                                                         "meetingParticipantSession is null: principalid = {0} scoid= {1} msk = {2}",
                                                                                         principalid, scoid, msk));
                }
            } else {
                Extensions.LogServiceCall("[IndexController][Result]", string.Format(
                                                                                     "meeting is null: principalid = {0} scoid= {1} DateTime.UtcNow.DayOfYear = {2} DateTime.Now.DayOfYear = {3}",
                                                                                     principalid, scoid, DateTime.UtcNow.DayOfYear, DateTime.Now.DayOfYear));
            }
            resultView.Result = (int) result;
            return View("result", resultView);
        }
    }
}

Commits for CPE_learningsiteCPE/CPE.App/CPE.App.Web/Controllers/IndexController.cs

Diff revisions: vs.
Revision Author Commited Message
831ee4 ... Diff Diff v.shishlov Sun 27 Feb, 2022 12:51:45 +0000

If possible create a couple of additional account with ADMIN permission. I hope their site is not written with hardcoded permissions based on user name "admin"

d90493 ... Diff Diff v.shishlov Sun 29 Aug, 2021 15:28:47 +0000

add ssl 1.2

4cd176 ... v.shishlov Fri 27 Aug, 2021 14:33:17 +0000

initial commit