예제 #1
0
 public bool DoesEmailExist(string email)
 {
     using (TicketingApp db = new TicketingApp())
     {
         var user = db.User.Where(u => u.email == email).FirstOrDefault();
         return(user != null);
     }
 }
예제 #2
0
        public ActionResult Login(User user, string returnUrl = "")
        {
            KillUserCookie();
            using (TicketingApp db = new TicketingApp())
            {
                var loggedInUser = db.User.Where(u => u.email == user.email).FirstOrDefault();
                if (loggedInUser != null)
                {
                    if (Crypto.VerifyHashedPassword(loggedInUser.password, user.password))
                    {
                        //Check if user is verified
                        if (!loggedInUser.isEmailVerified)
                        {
                            ModelState.AddModelError("", "Your email isn't verified. Please verify it before logging in.");
                            return(View());
                        }

                        //Checking the role
                        MailAddress address    = new MailAddress(loggedInUser.email);
                        string      identifier = address.Host;

                        var role = db.RoleIdentifier
                                   .Join(db.RoleIdentifierDetails,
                                         roleIdentifier => roleIdentifier.roleIdentifierID,
                                         roleIdentifierDetails => roleIdentifierDetails.RoleIdentifier.roleIdentifierID,
                                         (roleIdentifier, roleIdentifierDetails) => new { RoleIdentifier = roleIdentifier, RoleIdentifierDetails = roleIdentifierDetails })
                                   .Where(roleAndDetails => roleAndDetails.RoleIdentifierDetails.identifier == identifier).FirstOrDefault();

                        if (Url.IsLocalUrl(returnUrl))
                        {
                            return(Redirect(returnUrl));
                        }
                        else
                        {
                            // Making the Cookie
                            HttpCookie httpCookie = new HttpCookie("UserCookie");

                            httpCookie["UserID"]   = loggedInUser.recordID.ToString();
                            httpCookie["UserRole"] = role.RoleIdentifier.role;
                            httpCookie.Expires     = DateTime.Now.AddMinutes(30);
                            Response.Cookies.Add(httpCookie);
                            return(RedirectToAction("Index", Request.Cookies["UserCookie"]["UserRole"].ToString()));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "The username or password is wrong");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The username or password is wrong");
                }
            }
            return(View());
        }
예제 #3
0
        // GET: Proposal
        public ActionResult Index()
        {
            using (TicketingApp db = new TicketingApp())
            {
                var proposals = db.Proposal.ToList();

                if (proposals != null)
                {
                    return(View(proposals));
                }
                else
                {
                    return(View());
                }
            }
        }
예제 #4
0
 public ActionResult AdminIndex()
 {
     if (IsLoggedIn())
     {
         using (TicketingApp db = new TicketingApp())
         {
             var user      = db.User.Where(u => u.recordID == 999999).FirstOrDefault();
             var viewModel = new ViewModelBase
             {
                 user = user
             };
             return(View(viewModel));
         }
     }
     return(RedirectToAction("AdminLogin"));
 }
예제 #5
0
 public ActionResult Notifications(FormCollection formCollection)
 {
     if (IsLoggedIn() && IsAuthorized())
     {
         using (TicketingApp db = new TicketingApp())
         {
             TempData["message"]             = "This is a test notification sent at " + DateTime.Now.ToLongTimeString();
             TempData["targetURL"]           = "/User/Login";
             TempData["users"]               = db.User.ToList();
             TempData["returnURLName"]       = "Login";
             TempData["returnURLController"] = "User";
             return(RedirectToAction("Create", "Notification", new { area = "" }));
         }
     }
     else
     {
         return(RedirectToAction("Login", "User"));
     }
 }
예제 #6
0
        public ActionResult Create(string message, string targetURL, List <User> users, string returnURLName, string returnURLController)
        {
            try
            {
                // Let's create a notification
                foreach (var user in users)
                {
                    var notification = new Notification();
                    notification.message = message;
                    notification.url     = targetURL;
                    notification.isRead  = false;

                    using (TicketingApp db = new TicketingApp())
                    {
                        db.Configuration.ValidateOnSaveEnabled = false;
                        var temp = db.User.Where(u => u.recordID == user.recordID).FirstOrDefault();
                        temp.Notification.Add(notification);
                        db.Notification.Add(notification);
                        db.SaveChanges();
                    }

                    if (user.emailNotification == true)
                    {
                        using (TicketingApp db = new TicketingApp())
                        {
                            //Getting system user data
                            var sysUser = db.User.Where(u => u.recordID == 999999).FirstOrDefault();
                            SendNotificationEmail(message, targetURL, user, sysUser);
                        }
                    }
                }

                return(RedirectToAction(returnURLName, returnURLController));
            }
            catch
            {
                return(View());
            }
        }
예제 #7
0
        public ActionResult ForgotPassword(string email)
        {
            bool   status  = false;
            string message = "";

            using (TicketingApp db = new TicketingApp())
            {
                var user = db.User.Where(u => u.email == email).FirstOrDefault();

                if (user != null)
                {
                    db.Configuration.ValidateOnSaveEnabled = false;

                    //Giving the user a new GUID
                    user.activationCode = Guid.NewGuid();
                    db.SaveChanges();

                    // Sending Password Reset Email
                    string subject = "Ticketing App - Forgot Password";

                    string body = "<br/><br/>If this wasn't done by you then please ignore this email. " +
                                  "Otherwise Please Click on the link below to reset your password.";
                    string targetUrl = "/User/ResetPassword/";
                    //Getting system user data
                    var sysUser = db.User.Where(u => u.recordID == 999999).FirstOrDefault();
                    SendVerificationEmail(user.recordID, user.email, user.activationCode.ToString(), targetUrl, subject, body, sysUser);
                    status  = true;
                    message = "Please check your email for a reset password link.";
                }
                else
                {
                    message = "We can't seem to find your email. Are you sure it's enterred correctly?";
                }
            }
            ViewBag.Status  = status;
            ViewBag.Message = message;
            return(View());
        }
예제 #8
0
        public ActionResult ResetPassword(int?id, string ac)
        {
            bool   status  = false;
            string message = null;
            User   user    = new Models.User();

            using (TicketingApp db = new TicketingApp())
            {
                if (ac != null)
                {
                    user = db.User.Where(u => u.activationCode == new Guid(ac) && u.recordID == id).FirstOrDefault();
                }
                else
                {
                    user = null;
                }

                db.Configuration.ValidateOnSaveEnabled = false;
                if (user != null)
                {
                    user.activationCode = Guid.Empty;
                    db.SaveChanges();
                }
                else
                {
                    message = "Maybe you're not authorized to see this page. We're also confused how did you end up here";
                }
            }
            ViewBag.Status  = status;
            ViewBag.Message = message;
            return(View("ResetPassword", new User
            {
                recordID = user.recordID,
                firstName = user.firstName,
                email = user.email
            }));
        }
예제 #9
0
        public ActionResult Create(ProposalIdeaFieldViewModel proposalIdeaFieldViewModel)
        {
            try
            {
                // TODO: Add insert logic here
                using (TicketingApp db = new TicketingApp())
                {
                    proposalIdeaFieldViewModel.AllFields     = db.Fields.ToList();
                    proposalIdeaFieldViewModel.AllSupervisor = db.Supervisor.ToList();

                    int userID = GetUserID();
                    var user   = db.User.Where(u => u.recordID == userID).FirstOrDefault();
                    var idea   = new Idea
                    {
                        title       = proposalIdeaFieldViewModel.proposal.nameOfProject,
                        description = proposalIdeaFieldViewModel.proposal.abstrac,
                        type        = proposalIdeaFieldViewModel.idea.type,
                        field       = proposalIdeaFieldViewModel.idea.field,
                        User        = user
                    };
                    db.Idea.Add(idea);
                    db.SaveChanges();
                    int ideaRecordId = idea.recordID;
                    var ideaCreated  = db.Idea.Where(i => i.recordID == ideaRecordId).FirstOrDefault();
                    proposalIdeaFieldViewModel.proposal.User = user;
                    proposalIdeaFieldViewModel.proposal.Idea = ideaCreated;
                    db.Proposal.Add(proposalIdeaFieldViewModel.proposal);

                    var ticket = new Ticket
                    {
                        title         = proposalIdeaFieldViewModel.proposal.nameOfProject,
                        status        = "Pending",
                        timesRejected = 0,
                        User          = user,
                        Idea          = ideaCreated
                    };
                    db.Ticket.Add(ticket);
                    db.SaveChanges();
                    int ticketRecordId = ticket.recordID;
                    var ticketCreated  = db.Ticket.Where(t => t.recordID == ticketRecordId).FirstOrDefault();

                    string userRole    = GetUserRole();
                    var    contributor = new Contributors
                    {
                        status = "Pending",
                        role   = userRole,
                        User   = user,
                        Ticket = ticketCreated
                    };
                    db.Contributor.Add(contributor);
                    db.SaveChanges();
                    var surperUser = db.User.Where(u => u.recordID == proposalIdeaFieldViewModel.supervisor).FirstOrDefault();



                    var identifier     = surperUser.email;
                    var surperUserRole = db.RoleIdentifier
                                         .Join(db.RoleIdentifierDetails,
                                               roleIdentifier => roleIdentifier.recordID,
                                               roleIdentifierDetails => roleIdentifierDetails.RoleIdentifier.recordID,
                                               (roleIdentifier, roleIdentifierDetails) => new { RoleIdentifier = roleIdentifier, RoleIdentifierDetails = roleIdentifierDetails })
                                         .Where(roleAndDetails => identifier.Contains(roleAndDetails.RoleIdentifierDetails.identifier)).FirstOrDefault();

                    contributor.User = surperUser;
                    contributor.role = surperUserRole.RoleIdentifier.role;
                    db.Contributor.Add(contributor);
                    db.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            catch
            {
                var fields      = db.Fields.ToList();
                var supervisors = db.Supervisor.ToList();
                var viewModel   = new ProposalIdeaFieldViewModel
                {
                    AllFields     = fields,
                    AllSupervisor = supervisors
                };
                return(View(viewModel));
            }
        }
예제 #10
0
        // GET: Proposal/ExportPDF
        public ActionResult ExportPDF(int recordID)
        {
            Proposal proposals;
            Idea     ideas;
            Fields   field;

            using (TicketingApp db = new TicketingApp())
            {
                proposals = db.Proposal.Where(u => u.recordID == recordID).FirstOrDefault();
                ideas     = db.Idea.Where(idea => idea == proposals.Idea).FirstOrDefault();
            }

            Document document = new Document(PageSize.A4, 10f, 10f, 10f, 10f);

            //var output = new FileStream(Server.MapPath("MyFirstPDF.pdf"), FileMode.Create);


            using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
            {
                var writer = PdfWriter.GetInstance(document, memoryStream);
                document.Open();


                //var logo = iTextSharp.text.Image.GetInstance(Server.MapPath("~/ABsIS_Logo.jpg"));
                //logo.SetAbsolutePosition(430, 770);
                //logo.ScaleAbsoluteHeight(30);
                //logo.ScaleAbsoluteWidth(70);
                //document.Add(logo);

                PdfPTable table1 = new PdfPTable(1);
                //table1.PaddingTop = 2f;
                PdfPCell cell11 = new PdfPCell();
                cell11.Border = Rectangle.NO_BORDER;
                Phrase phrase = null;

                phrase = new Paragraph();

                phrase.Add(new Chunk("Project Proposal\n\n\n", FontFactory.GetFont("Arial", 20, Font.BOLD, BaseColor.BLACK)));

                phrase.Add(new Chunk("Name of the Project :\n", FontFactory.GetFont("Arial", 16, Font.BOLD, BaseColor.BLACK)));
                phrase.Add(new Chunk(proposals.nameOfProject + "\n\n", FontFactory.GetFont("Arial", 14, Font.NORMAL, BaseColor.BLACK)));

                phrase.Add(new Chunk("Abstract :\n", FontFactory.GetFont("Arial", 16, Font.BOLD, BaseColor.BLACK)));
                phrase.Add(new Chunk(proposals.abstrac + "\n\n", FontFactory.GetFont("Arial", 14, Font.NORMAL, BaseColor.BLACK)));

                phrase.Add(new Chunk("Proposal Type :\n", FontFactory.GetFont("Arial", 16, Font.BOLD, BaseColor.BLACK)));
                phrase.Add(new Chunk(ideas.type + "\n\n", FontFactory.GetFont("Arial", 14, Font.NORMAL, BaseColor.BLACK)));


                phrase.Add(new Chunk("Introduction :\n", FontFactory.GetFont("Arial", 16, Font.BOLD, BaseColor.BLACK)));
                phrase.Add(new Chunk(proposals.introduction + "\n\n", FontFactory.GetFont("Arial", 14, Font.NORMAL, BaseColor.BLACK)));


                phrase.Add(new Chunk("Overall Description :\n", FontFactory.GetFont("Arial", 16, Font.BOLD, BaseColor.BLACK)));
                phrase.Add(new Chunk(proposals.overallDescription + "\n\n", FontFactory.GetFont("Arial", 14, Font.NORMAL, BaseColor.BLACK)));


                phrase.Add(new Chunk("Function Requirements :\n", FontFactory.GetFont("Arial", 16, Font.BOLD, BaseColor.BLACK)));
                phrase.Add(new Chunk(proposals.functionalRequirements + "\n\n", FontFactory.GetFont("Arial", 14, Font.NORMAL, BaseColor.BLACK)));


                phrase.Add(new Chunk("Non-Function Requirements :\n", FontFactory.GetFont("Arial", 16, Font.BOLD, BaseColor.BLACK)));
                phrase.Add(new Chunk(proposals.nonFunctionalRequirements + "\n\n", FontFactory.GetFont("Arial", 14, Font.NORMAL, BaseColor.BLACK)));

                phrase.Add(new Chunk("Project Technologies :\n", FontFactory.GetFont("Arial", 16, Font.BOLD, BaseColor.BLACK)));
                phrase.Add(new Chunk(proposals.projectTechnologies + "\n\n", FontFactory.GetFont("Arial", 14, Font.NORMAL, BaseColor.BLACK)));


                phrase.Add(new Chunk("Result: :\n", FontFactory.GetFont("Arial", 16, Font.BOLD, BaseColor.BLACK)));
                phrase.Add(new Chunk(proposals.result + "\n\n", FontFactory.GetFont("Arial", 14, Font.NORMAL, BaseColor.BLACK)));

                cell11.AddElement(phrase);
                cell11.VerticalAlignment = Element.ALIGN_RIGHT;

                table1.AddCell(cell11);



                document.Add(table1);
                document.Close();
                byte[] bytes = memoryStream.ToArray();
                memoryStream.Close();
                Response.Clear();
                Response.AddHeader("Content-Disposition", "attachment; filename=Proposal.pdf");
                Response.ContentType = "application/pdf";
                Response.Buffer      = true;
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.BinaryWrite(bytes);
                Response.End();
                Response.Close();
            }
            return(null);
        }
예제 #11
0
        public ActionResult Create(ProposalIdeaFieldViewModel proposalIdeaFieldViewModel)
        {
            try
            {
                // TODO: Add insert logic here
                using (TicketingApp db = new TicketingApp())
                {
                    proposalIdeaFieldViewModel.AllFields     = db.Fields.ToList();
                    proposalIdeaFieldViewModel.AllSupervisor = db.Supervisor.ToList();

                    int userID1 = GetUserID();
                    var user1   = db.User.Where(u => u.recordID == userID1).FirstOrDefault();
                    var idea1   = new Idea
                    {
                        title       = proposalIdeaFieldViewModel.proposal.nameOfProject,
                        description = proposalIdeaFieldViewModel.proposal.abstrac,
                        type        = proposalIdeaFieldViewModel.idea.type,
                        field       = proposalIdeaFieldViewModel.idea.field,
                        User        = user1
                    };
                    db.Idea.Add(idea1);
                    db.SaveChanges();
                    int ideaRecordId = idea1.recordID;
                    var ideaCreated  = db.Idea.Where(i => i.recordID == ideaRecordId).FirstOrDefault();
                    proposalIdeaFieldViewModel.proposal.User = user1;
                    proposalIdeaFieldViewModel.proposal.Idea = ideaCreated;
                    db.Proposal.Add(proposalIdeaFieldViewModel.proposal);

                    var ticket1 = new Ticket
                    {
                        title         = proposalIdeaFieldViewModel.proposal.nameOfProject,
                        status        = "Pending",
                        timesRejected = 0,
                        User          = user1,
                        Idea          = ideaCreated
                    };
                    db.Ticket.Add(ticket1);
                    db.SaveChanges();
                    int ticketRecordId = ticket1.recordID;
                    var ticketCreated  = db.Ticket.Where(t => t.recordID == ticketRecordId).FirstOrDefault();

                    string userRole    = GetUserRole();
                    var    contributor = new Contributors
                    {
                        status = "Pending",
                        Role   = userRole,
                        User   = user1,
                        Ticket = ticketCreated
                    };
                    db.Contributors.Add(contributor);
                    db.SaveChanges();
                    var surperUser = db.User.Where(u => u.recordID == proposalIdeaFieldViewModel.supervisor).FirstOrDefault();



                    var identifier     = surperUser.email;
                    var surperUserRole = db.RoleIdentifier
                                         .Join(db.RoleIdentifierDetails,
                                               roleIdentifier => roleIdentifier.recordID,
                                               roleIdentifierDetails => roleIdentifierDetails.RoleIdentifier.recordID,
                                               (roleIdentifier, roleIdentifierDetails) => new { RoleIdentifier = roleIdentifier, RoleIdentifierDetails = roleIdentifierDetails })
                                         .Where(roleAndDetails => identifier.Contains(roleAndDetails.RoleIdentifierDetails.identifier)).FirstOrDefault();

                    contributor.User = surperUser;
                    contributor.Role = surperUserRole.RoleIdentifier.role;
                    db.Contributors.Add(contributor);
                    db.SaveChanges();
                }
                int userID = GetUserID();

                var user     = db.User.Where(u => u.recordID == userID).FirstOrDefault();
                var student  = db.Student.Where(s => s.recordID == userID).FirstOrDefault();
                var ticket   = db.Ticket.Where(t => t.Contributors.Any(c => c.User.recordID == userID)).FirstOrDefault();
                var idea     = db.Idea.Where(i => i.User.recordID != userID).ToList();
                var proposal = db.Proposal.Where(p => p.User.recordID == userID).ToList();

                var proposalUser = new ProposalUserViewModel
                {
                    user           = user,
                    student        = student,
                    ticket         = ticket,
                    availableIdeas = idea,
                    proposals      = proposal
                };
                return(View("Index", proposalUser));
            }
            catch
            {
            }
        }
예제 #12
0
        public ActionResult Register(User user)
        {
            bool   status     = false;
            string message    = "";
            string roleOfUser = "";

            if (ModelState.IsValid)
            {
                //Check if Email already exists
                var emailExists = DoesEmailExist(user.email);

                if (emailExists)
                {
                    ModelState.AddModelError("EmailExists", "The email you provided already exists");
                    return(View(user));
                }

                //Generating Activation Code
                user.activationCode = Guid.NewGuid();

                //Hashing the Password
                user.password        = Crypto.HashPassword(user.password);
                user.confirmPassword = user.password; // To avoid EntityValidationError

                user.isEmailVerified   = false;
                user.emailNotification = true;

                using (TicketingApp db = new TicketingApp())
                {
                    //Checking the role of the user registering
                    MailAddress address    = new MailAddress(user.email);
                    string      identifier = address.Host;

                    var role = db.RoleIdentifier
                               .Join(db.RoleIdentifierDetails,
                                     roleIdentifier => roleIdentifier.roleIdentifierID,
                                     roleIdentifierDetails => roleIdentifierDetails.RoleIdentifier.roleIdentifierID,
                                     (roleIdentifier, roleIdentifierDetails) => new { RoleIdentifier = roleIdentifier, RoleIdentifierDetails = roleIdentifierDetails })
                               .Where(roleAndDetails => roleAndDetails.RoleIdentifierDetails.identifier == identifier).FirstOrDefault();
                    if (role != null)
                    {
                        db.User.Add(user);
                        if (role.RoleIdentifier.role == "Student")
                        {
                            Student student = new Student();
                            student.recordID = user.recordID;
                            student.userType = "Student";
                            db.Student.Add(student);
                            db.SaveChanges();
                            roleOfUser = "******";
                        }
                        else if (role.RoleIdentifier.role == "Supervisor")
                        {
                            Supervisor supervisor = new Supervisor();
                            supervisor.recordID = user.recordID;
                            supervisor.userType = "Supervisor";
                            db.Supervisor.Add(supervisor);
                            db.SaveChanges();
                            roleOfUser = "******";
                        }

                        // Sending Activation Email
                        string subject = "Your account is successfully created";

                        string body = "<br/><br/>So you want to join the ticketing world? One more step and you're done." +
                                      " Please Click on the link below to verify your account.";
                        string targetUrl = "/User/VerifyAccount/";
                        //Getting system user data
                        var sysUser = db.User.Where(u => u.recordID == 999999).FirstOrDefault();
                        SendVerificationEmail(user.recordID, user.email, user.activationCode.ToString(), targetUrl, subject, body, sysUser);
                        status  = true;
                        message = "Your account is now created. Please check your email for an activation code.";
                    }
                    else
                    {
                        message = "Your email maybe valid but seems like you're not recognized by our system. Please check if it's correct.";
                    }
                }
                ModelState.Clear();
            }
            else
            {
                message = "Something weird happened. Developers, could you check the Register Action in your controller?";
            }

            ViewBag.role    = roleOfUser;
            ViewBag.message = message;
            ViewBag.status  = status;

            return(View(user));
        }