// GET: Violation
        public ActionResult Index()
        {
            var vm            = new ViolationViewModel();
            var db            = new CPPdatabaseEntities();
            var thisCppUserId = CppUserService.GetCppUserId(User.Identity.GetUserId(), db);
            var sessions      =
                db.SessionLogs.Where(session => session.CallReceiverId == thisCppUserId)
                .Select(session => session.CallSenderId)
                .ToList();

            sessions.AddRange(db.SessionLogs.Where(session => session.CallSenderId == thisCppUserId).Select(session => session.CallReceiverId));

            foreach (var partnerId in sessions)
            {
                //vm.List.Add(db.CppUsers.Where(u => u.Id == partnerId).Select(u => u.AspNetUser).Single());
                vm.List.Add(db.CppUsers.Where(u => u.Id == partnerId).Select(x => new AspNetUserDTO()
                {
                    Email    = x.AspNetUser.Email,
                    Id       = x.AspNetUser.Id,
                    UserName = x.AspNetUser.UserName
                }).Single());
            }

            return(View(vm));
        }
        public ActionResult Contact()
        {
            ViewBag.Message = "Contact ODU's Spring 2017 CS411W Red Team";
            var usr           = User.Identity.GetUserId();
            var vm            = new ViolationViewModel();
            var db            = new CPPdatabaseEntities();
            var thisCppUserId = CppUserService.GetCppUserId(User.Identity.GetUserId(), db);
            var sessions      =
                db.SessionLogs.Where(session => session.CallReceiverId == thisCppUserId)
                .Select(session => session.CallSenderId)
                .ToList();

            sessions.AddRange(db.SessionLogs.Where(session => session.CallSenderId == thisCppUserId).Select(session => session.CallReceiverId));

            foreach (var partnerId in sessions)
            {
                //vm.List.Add(db.CppUsers.Where(u => u.Id == partnerId).Select(u => u.AspNetUser).Single());
                vm.List.Add(db.CppUsers.Where(u => u.Id == partnerId).Select(x => new AspNetUserDTO()
                {
                    Email    = x.AspNetUser.Email,
                    Id       = x.AspNetUser.Id,
                    UserName = x.AspNetUser.UserName
                }).Single());
            }
            var withoutDupes = vm.List.GroupBy(user => user.Email).Select(group => group.First());

            vm.List = withoutDupes.ToList();
            ViewData["ViolationList"] = vm.List;
            //ViewData["userIsAdmin"] = db.CppUsers.Where(x => x.AspNetUserId == usr).Select(x => x.PermissionLevel).Single() == 1;
            ViewBag.ListItems       = vm.List;
            ViewData["userIsAdmin"] = db.CppUsers.Single(x => x.Id == thisCppUserId).PermissionLevel == 1;
            return(View());
        }
Esempio n. 3
0
        public static bool SendEmailRequest(string sourceEmail, string recipientEmail, string session)
        {
            string senderName;
            int    senderCppUserId;
            int    recipientCppUserId;

            using (var dc = new CPPdatabaseEntities())
            {
                var senderProfile = dc.Profiles.SingleOrDefault(p => p.CppUser.AspNetUser.Email == sourceEmail);
                if (senderProfile != null)
                {
                    senderName = senderProfile.FirstName + " " + senderProfile.LastName;
                }
                else
                {
                    senderName = sourceEmail;
                }

                senderCppUserId =
                    dc.CppUsers.Where(u => u.AspNetUser.Email == sourceEmail).Select(u => u.Id).SingleOrDefault();

                recipientCppUserId =
                    dc.CppUsers.Where(u => u.AspNetUser.Email == recipientEmail).Select(u => u.Id).SingleOrDefault();
            }

            MailMessage callRequestEmail = new MailMessage();

            callRequestEmail.From = new MailAddress(sourceEmail);
            callRequestEmail.To.Add(recipientEmail);
            callRequestEmail.Subject = senderName + " has requested a conversation! " + DateTime.Now.ToString();
            //callRequestEmail.Body = "Click this link to join the session https://appr.tc/r/" + session +
            //						" and then click Join to to enter the call.";
            callRequestEmail.Body = "Click this link to join the session http://localhost:61441/Call/InitiateCall?session=" + session + "&sender=" + senderCppUserId + "&recipient=" + recipientCppUserId + " and then click Join to to enter the call.";
            SmtpClient client = new SmtpClient();

            client.UseDefaultCredentials = true;
            client.Host           = "smtp.gmail.com";
            client.Port           = 587;
            client.EnableSsl      = true;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.Credentials    = new NetworkCredential("*****@*****.**", "Redteam17");
            client.Timeout        = 20000;
            try
            {
                client.Send(callRequestEmail);
            }
            catch (Exception ex)
            {
                return(false);
            }
            finally
            {
                callRequestEmail.Dispose();
            }

            return(true);
        }
Esempio n. 4
0
 public static void EndSessionLog(int sessionId)
 {
     using (var dc = new CPPdatabaseEntities())
     {
         var unfinishedSession = dc.SessionLogs.Single(s => s.Id == sessionId);
         unfinishedSession.SessionEnd = DateTime.Now.TimeOfDay;
         dc.SaveChanges();
     }
 }
        public static Profile GetProfile(int cppUserId)
        {
            Profile profile;

            using (var dc = new CPPdatabaseEntities())
            {
                profile = dc.Profiles.Single(prof => prof.CppUserId == cppUserId);
            }

            return(profile);
        }
Esempio n. 6
0
        public static void BeginSessionLog(int senderId, int receiverId, string sessionString)
        {
            var sessionLog = new SessionLog()
            {
                CallSenderId   = senderId,
                CallReceiverId = receiverId,
                SessionBegin   = DateTime.Now.TimeOfDay,
                SessionEnd     = null,
                SessionString  = sessionString,
                Date           = DateTime.Today
            };

            using (var dc = new CPPdatabaseEntities())
            {
                dc.SessionLogs.Add(sessionLog);
                dc.SaveChanges();
            }
        }
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    //Create CPP user using aspnetuserid as fk to aspnetusers table
                    using (var dc = new CPPdatabaseEntities())
                    {
                        var newCppUser = new CppUser
                        {
                            AspNetUserId    = user.Id,
                            PermissionLevel = 0,
                            School          = 0,
                            LastActive      = System.DateTime.Now.ToUniversalTime()
                        };
                        dc.CppUsers.Add(newCppUser);
                        dc.SaveChanges();
                    }

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
 public static List <Contact> GetContactList(int ownerId, CPPdatabaseEntities dc)
 {
     return(dc.Contacts.Where(con => con.ContactListOwnerId == ownerId).ToList());
 }
Esempio n. 9
0
        public static bool SendViolationEmail(int violationCode, int reportedId, string sourceEmail)
        {
            var    db = new CPPdatabaseEntities();
            string senderName;
            int    senderCppUserId;
            int    recipientCppUserId;

            var recipientEmail = "*****@*****.**";
            var SourceEmail    = sourceEmail;

            using (var dc = new CPPdatabaseEntities())
            {
                var senderProfile = dc.Profiles.SingleOrDefault(p => p.CppUser.AspNetUser.Email == SourceEmail);
                if (senderProfile != null)
                {
                    senderName = senderProfile.FirstName + " " + senderProfile.LastName;
                }
                else
                {
                    senderName = SourceEmail;
                }

                senderCppUserId =
                    dc.CppUsers.Where(u => u.AspNetUser.Email == SourceEmail).Select(u => u.Id).SingleOrDefault();

                recipientCppUserId =
                    dc.CppUsers.Where(u => u.AspNetUser.Email == recipientEmail).Select(u => u.Id).SingleOrDefault();
            }

            MailMessage callRequestEmail = new MailMessage();
            var         msg = db.ViolationTypes.Where(x => x.Id == violationCode).Select(x => x.Description).Single();

            callRequestEmail.From = new MailAddress(SourceEmail);
            callRequestEmail.To.Add(recipientEmail);
            callRequestEmail.Subject = senderName + " has reported a violation! " + DateTime.Now.ToString();
            //callRequestEmail.Body = "Click this link to join the session https://appr.tc/r/" + session +
            //						" and then click Join to to enter the call.";
            callRequestEmail.Body = "Violation Code: " + msg + ", Reported Id: " + CppUserService.GetCppUserEmail2(reportedId, db);
            SmtpClient client = new SmtpClient();

            client.UseDefaultCredentials = true;
            client.Host           = "smtp.gmail.com";
            client.Port           = 587;
            client.EnableSsl      = true;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.Credentials    = new NetworkCredential("*****@*****.**", "Redteam17");
            client.Timeout        = 20000;
            try
            {
                client.Send(callRequestEmail);
            }
            catch (Exception ex)
            {
                return(false);
            }
            finally
            {
                callRequestEmail.Dispose();
            }

            return(true);
        }
 public static int GetCppUserId(string aspNetUserId, CPPdatabaseEntities dc)
 {
     return(dc.CppUsers.Where(c => c.AspNetUserId == aspNetUserId).Select(c => c.Id).SingleOrDefault());
 }
 public static string GetCppUserEmail2(int cppUserId, CPPdatabaseEntities dc)
 {
     return(dc.AspNetUsers.Where(u => u.CppUsers.FirstOrDefault().Id == cppUserId).Select(u => u.Email).SingleOrDefault());
 }
 public static string GetCppUserEmail(string aspNetUserId, CPPdatabaseEntities dc)
 {
     return(dc.CppUsers.Where(c => c.AspNetUserId == aspNetUserId).Select(c => c.AspNetUser.Email).ToString());
 }