Ejemplo n.º 1
0
        public ActionResult New(FormCollection frm)
        {
            var model = new bat.logic.ViewModels.Lessons.New();

            try
            {
                var user = new logic.Rules.Authentication(Request.GetOwinContext()).GetLoggedInUser();
                if (user == null)
                {
                    return(RedirectToRoute("home"));
                }

                var accInfo = logic.Helpers.UserAccountInfo.Get(user.ID);
                if (!accInfo.IsTeacher || !accInfo.IsEnabled)
                {
                    return(RedirectToRoute("home"));
                }

                model = _lessonsService.SaveNew(frm, user.ID);
            }
            catch (Exception ex)
            {
                ViewBag.Error     = ex.Message;
                TempData["Error"] = ex.Message;
            }

            return(RedirectToAction("Index", new { id = model.lesson.ID }));
        }
Ejemplo n.º 2
0
        public ActionResult Index(
            string type, string firstname, string lastname, string email, string password)
        {
            var user = new logic.Rules.Authentication(Request.GetOwinContext()).GetLoggedInUser();

            if (user != null)
            {
                return(RedirectToRoute("home"));
            }

            var model = new bat.logic.ViewModels.Homepage.Landing();

            try
            {
                ViewBag.firstName = firstname;
                ViewBag.lastName  = lastname;
                ViewBag.email     = email;
                model             = _homeService.Signup(Convert.ToInt32(type), firstname, lastname, email, password);

                var auth = new logic.Rules.Authentication(Request.GetOwinContext());
                auth.Login(auth.GetUser(email, password));
                return(RedirectToRoute("home"));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                return(View("Landing", model));
            }
        }
Ejemplo n.º 3
0
        public ActionResult Join(int id)
        {
            var model = new bat.logic.ViewModels.Lessons.Join();

            try
            {
                var user = new logic.Rules.Authentication(Request.GetOwinContext()).GetLoggedInUser();
                if (user == null)
                {
                    return(RedirectToRoute("home"));
                }

                model = _lessonsService.LoadJoin(id, user.ID);

                if (!model.CanContinue)
                {
                    return(RedirectToAction("Index", "Lessons", new { id = id }));
                }
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
            }

            return(View(model));
        }
Ejemplo n.º 4
0
        public ActionResult Cancel(int id, FormCollection frm)
        {
            var model = new logic.ViewModels.Lessons.Cancel();

            try
            {
                var user = new logic.Rules.Authentication(Request.GetOwinContext()).GetLoggedInUser();
                if (user == null)
                {
                    return(RedirectToRoute("home"));
                }

                var accInfo = logic.Helpers.UserAccountInfo.Get(user.ID);
                if (!accInfo.IsTeacher)
                {
                    return(RedirectToRoute("home"));
                }

                model = _lessonsService.LoadCancel(id, user.ID);
                _lessonsService.SaveCancel(id, user.ID, frm);
            }
            catch (WrongAccountException)
            {
                return(RedirectToRoute("home"));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                return(View("Error", model));
            }

            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 5
0
        public ActionResult Leave(int lessonid, int studentid, FormCollection frm)
        {
            var model = new bat.logic.ViewModels.Lessons.Leave();

            try
            {
                var user = new logic.Rules.Authentication(Request.GetOwinContext()).GetLoggedInUser();
                if (user == null)
                {
                    return(RedirectToRoute("home"));
                }

                model = _lessonsService.LoadLeave(lessonid, user.ID);

                if (!model.CanContinue)
                {
                    return(RedirectToAction("Index", "Lessons", new { id = lessonid }));
                }

                _lessonsService.SaveLeave(lessonid, studentid);

                return(RedirectToRoute("home"));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
            }
            return(RedirectToRoute("home"));
        }
Ejemplo n.º 6
0
        public ActionResult DeleteMember(int id)
        {
            var user = new logic.Rules.Authentication(Request.GetOwinContext()).GetLoggedInUser();

            if (user == null)
            {
                return(RedirectToRoute("home"));
            }

            var model = new bat.logic.ViewModels.Profile.EditMember();

            try
            {
                var accInfo = logic.Helpers.UserAccountInfo.Get(user.ID);
                if (accInfo.IsTeacher)
                {
                    RedirectToAction("Index");
                }

                model = _profileService.DeleteEditMember(id, user.ID);
            }
            catch (WrongAccountException)
            {
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 7
0
        public ActionResult New(string date)
        {
            var model = new bat.logic.ViewModels.Lessons.New();

            try
            {
                var user = new logic.Rules.Authentication(Request.GetOwinContext()).GetLoggedInUser();
                if (user == null)
                {
                    return(RedirectToRoute("home"));
                }

                var accInfo = logic.Helpers.UserAccountInfo.Get(user.ID);
                if (!accInfo.IsTeacher || !accInfo.IsEnabled)
                {
                    return(RedirectToRoute("home"));
                }

                model = _lessonsService.LoadNew(date);
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
            }

            return(View(model));
        }
Ejemplo n.º 8
0
        public ActionResult New(FormCollection frm)
        {
            var user = new logic.Rules.Authentication(Request.GetOwinContext()).GetLoggedInUser();

            if (user == null)
            {
                return(RedirectToRoute("home"));
            }

            var model = new bat.logic.ViewModels.Profile.New();

            try
            {
                var accInfo = logic.Helpers.UserAccountInfo.Get(user.ID);
                if (accInfo.IsTeacher)
                {
                    return(RedirectToAction("Index"));
                }

                model = _profileService.SaveNew(user.ID, frm);
                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
            }
            return(View(model));
        }
Ejemplo n.º 9
0
        public ActionResult LessonDetails(int id)
        {
            var user = new logic.Rules.Authentication(Request.GetOwinContext()).GetLoggedInUser();

            if (user == null)
            {
                return(RedirectToRoute("home"));
            }

            var model = new bat.logic.ViewModels.Profile.LessonDetails();

            try
            {
                model = _profileService.LoadLessonDetails(id, user.ID);
            }
            catch (WrongAccountException)
            {
                return(RedirectToRoute("home"));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
            }

            return(View(model));
        }
Ejemplo n.º 10
0
        public ActionResult Edit(string FirstName, string LastName, string Description, string Qualifications, int?Rate, HttpPostedFileBase Picture)
        {
            var user = new logic.Rules.Authentication(Request.GetOwinContext()).GetLoggedInUser();

            if (user == null)
            {
                return(RedirectToRoute("home"));
            }

            var model = new bat.logic.ViewModels.Profile.Edit();

            try
            {
                model = _profileService.ProfileEditSave(
                    user.ID,
                    FirstName,
                    LastName,
                    Description,
                    Qualifications,
                    Rate,
                    Picture);

                return(RedirectToAction("Index"));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
            }
            return(View(model));
        }
Ejemplo n.º 11
0
        public ActionResult logout()
        {
            ViewData.Clear();
            TempData.Clear();
            Session.Clear();
            var auth = new logic.Rules.Authentication(Request.GetOwinContext());

            auth.Logout();

            return(RedirectToRoute("home"));
        }
Ejemplo n.º 12
0
        public ActionResult ForgotPassword()
        {
            ViewData.Clear();
            TempData.Clear();
            Session.Clear();
            var auth = new logic.Rules.Authentication(Request.GetOwinContext());

            auth.Logout();

            return(View());
        }
Ejemplo n.º 13
0
        public string UploadtoCloud(FormDataCollection formData)
        {
            var user = new logic.Rules.Authentication(HttpContext.Current.Request.GetOwinContext()).GetLoggedInUser();

            if (user == null)
            {
                throw new Exception("Unauthorised access.");
            }

            return(logic.Rules.ResourceManagement.UploadResourceImage(formData));
        }
Ejemplo n.º 14
0
        public string Getattachment(FormDataCollection formData)
        {
            var user = new logic.Rules.Authentication(HttpContext.Current.Request.GetOwinContext()).GetLoggedInUser();

            if (user == null)
            {
                throw new Exception("Unauthorised access.");
            }

            return(_lessonsService.GetImageStream(Convert.ToInt32(formData["attachmentid"])));
        }
Ejemplo n.º 15
0
        public ActionResult Login()
        {
            var user = new logic.Rules.Authentication(Request.GetOwinContext()).GetLoggedInUser();

            if (user != null)
            {
                return(RedirectToRoute("home"));
            }

            return(View());
        }
        public string Getday(FormDataCollection formData)
        {
            var user = new logic.Rules.Authentication(HttpContext.Current.Request.GetOwinContext()).GetLoggedInUser();

            if (user == null)
            {
                throw new Exception("Unauthorised access.");
            }

            var json = new JavaScriptSerializer();

            return(json.Serialize(_homeService.GDay(Convert.ToInt32(formData["userid"]), formData["date"])));
        }
Ejemplo n.º 17
0
        public ActionResult Index()
        {
            var user = new logic.Rules.Authentication(Request.GetOwinContext()).GetLoggedInUser();

            if (user == null)
            {
                user = new logic.Rules.Authentication(Request.GetOwinContext()).GetLoggedInAdminUser();
                if (user == null)
                {
                    return(RedirectToAction("Landing"));
                }

                return(RedirectToAction("Index", "Admin"));
            }

            var model = new bat.logic.ViewModels.Homepage.Dashboard();

            try
            {
                var accInfo = _accService.Get(user.ID);

                if (accInfo.IsTeacher &&
                    (string.IsNullOrEmpty(accInfo.account.Description) || string.IsNullOrEmpty(accInfo.account.Qualifications)))
                {
                    return(RedirectToAction("Complete", "Profile"));
                }

                model         = _homeService.LoadDashboard(accInfo.accountType, accInfo.account.ID);
                model.AccInfo = accInfo;
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                return(View("Error"));
            }

            switch (model.AccInfo.accountType)
            {
            case Types.AccountTypes.Student:
                return(View("DashStudent", model));

            case Types.AccountTypes.Teacher:
                return(View("DashTeacher", model));
            }

            // maybe for admin later
            return(View(model));
        }
Ejemplo n.º 18
0
        public ActionResult ListLessons(string subject)
        {
            var user  = new logic.Rules.Authentication(Request.GetOwinContext()).GetLoggedInUser();
            var model = new bat.logic.ViewModels.Homepage.SubjectList();

            try
            {
                model = _homeService.LoadSubjectList(subject, user?.ID);
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
            }

            return(View(model));
        }
Ejemplo n.º 19
0
        public ActionResult Upload(int id, HttpPostedFileBase data, string title)
        {
            try
            {
                var user = new logic.Rules.Authentication(Request.GetOwinContext()).GetLoggedInUser();
                if (user == null)
                {
                    return(RedirectToRoute("home"));
                }

                _lessonsService.UploadImage(id, title, data, user.ID);
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
            }

            return(RedirectToAction("Index", new { id = id }));
        }
Ejemplo n.º 20
0
        public ActionResult ResetPassword(string t)
        {
            var model = new bat.logic.ViewModels.Homepage.ResetPassword();

            try
            {
                ViewData.Clear();
                TempData.Clear();
                Session.Clear();
                var auth = new logic.Rules.Authentication(Request.GetOwinContext());
                auth.Logout();

                model = _passwdService.VerifyToken(t);
            }
            catch (Exception ex)
            {
                ViewBag.Response = ex.Message;
            }
            return(View(model));
        }
Ejemplo n.º 21
0
        public ActionResult ResetPassword(string token, string txtPassword1, string txtPassword2)
        {
            var model = new bat.logic.ViewModels.Homepage.ResetPassword();

            try
            {
                model = _passwdService.VerifyToken(token);
                var account = _passwdService.ChangePassword(token, txtPassword1, txtPassword2);

                var auth = new logic.Rules.Authentication(Request.GetOwinContext());
                auth.Login(account);

                return(RedirectToRoute("home"));
            }
            catch (Exception ex)
            {
                ViewBag.ErrMsg = ex.Message;
            }
            return(View(model));
        }
Ejemplo n.º 22
0
        public string Upload(FormDataCollection formData)
        {
            var user = new logic.Rules.Authentication(HttpContext.Current.Request.GetOwinContext()).GetLoggedInUser();

            if (user == null)
            {
                throw new Exception("Unauthorised access.");
            }

            var json = new JavaScriptSerializer();

            try
            {
                return(json.Serialize(_lessonsService.UploadEncodedImage(Convert.ToInt32(formData["lessonid"]), user.ID, formData["title"], formData["data"])));
            }
            catch (Exception e)
            {
                return(json.Serialize(e.Message));
            }
        }
Ejemplo n.º 23
0
        public ActionResult LoginSignup(string returnUrl)
        {
            var user = new logic.Rules.Authentication(Request.GetOwinContext()).GetLoggedInUser();

            //So that the user can be referred back to where they were when they click logon
            if (string.IsNullOrEmpty(returnUrl) && Request.UrlReferrer != null)
            {
                returnUrl = Server.UrlEncode(Request.UrlReferrer.PathAndQuery);
            }
            if (user != null)
            {
                return(RedirectToRoute("home"));
            }

            else if (Url.IsLocalUrl(returnUrl) && !string.IsNullOrEmpty(returnUrl))
            {
                ViewBag.ReturnURL = returnUrl;
            }
            return(View());
        }
Ejemplo n.º 24
0
        public ActionResult Index()
        {
            var user = new logic.Rules.Authentication(Request.GetOwinContext()).GetLoggedInUser();

            if (user == null)
            {
                return(RedirectToRoute("home"));
            }

            var model = new bat.logic.ViewModels.Profile.Profile();

            try
            {
                model.AccInfo = logic.Helpers.UserAccountInfo.Get(user.ID);
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
            }

            return(View(model));
        }
Ejemplo n.º 25
0
        public ActionResult Swap(int id)
        {
            var model = new logic.Rules.Swap();

            try
            {
                var user = new logic.Rules.Authentication(Request.GetOwinContext()).GetLoggedInUser();
                if (user == null)
                {
                    return(RedirectToRoute("home"));
                }

                model.Load(user, id);
                var auth = new logic.Rules.Authentication(Request.GetOwinContext());
                auth.Login(model.account);
            }
            catch (Exception ex)
            {
                ViewBag.LoginErrMsg = ex.Message;
            }

            return(RedirectToRoute("home"));
        }
Ejemplo n.º 26
0
        public string UploadFile()
        {
            var user = new logic.Rules.Authentication(HttpContext.Current.Request.GetOwinContext()).GetLoggedInUser();

            if (user == null)
            {
                throw new Exception("Unauthorised access.");
            }

            if (HttpContext.Current.Request.Files.AllKeys.Any())
            {
                // Get the uploaded image from the Files collection
                var httpPostedFile = HttpContext.Current.Request.Files["UploadedImage"];

                if (httpPostedFile != null)
                {
                    // Validate the uploaded image(optional)
                    return("success");
                }
                return("fail");
            }
            return("fail");
        }
Ejemplo n.º 27
0
        public ActionResult Reschedule(int id)
        {
            var model = new logic.ViewModels.Lessons.Reschedule();

            try
            {
                var user = new logic.Rules.Authentication(Request.GetOwinContext()).GetLoggedInUser();
                if (user == null)
                {
                    return(RedirectToRoute("home"));
                }

                var accInfo = logic.Helpers.UserAccountInfo.Get(user.ID);
                if (!accInfo.IsTeacher)
                {
                    return(RedirectToRoute("home"));
                }

                model = _lessonsService.LoadReschedule(id, user.ID);

                if (model.lesson.CancelledDate.HasValue)
                {
                    return(RedirectToAction("Index", new { id = id }));
                }

                return(View(model));
            }
            catch (WrongAccountException)
            {
                return(RedirectToRoute("home"));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                return(View("Error", model));
            }
        }
Ejemplo n.º 28
0
        public ActionResult Register(string type, string firstname, string lastname, string email, string password, string returnUrl)
        {
            try
            {
                ViewBag.firstName = firstname;
                ViewBag.lastName  = lastname;
                ViewBag.email     = email;
                var rs = _homeService.Signup(Convert.ToInt32(type), firstname, lastname, email, password);

                var auth = new logic.Rules.Authentication(Request.GetOwinContext());
                auth.Login(auth.GetUser(email, password));
            }
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                return(View("LoginSignup"));
            }

            //returnURL needs to be decoded
            string decodedUrl = "";

            if (!string.IsNullOrEmpty(returnUrl))
            {
                decodedUrl = Server.UrlDecode(returnUrl);
            }

            //Login logic...

            if (Url.IsLocalUrl(decodedUrl))
            {
                return(Redirect(decodedUrl));
            }
            else
            {
                return(RedirectToRoute("home"));
            }
        }
Ejemplo n.º 29
0
        public ActionResult login(string txtUsername, string txtPassword, string returnUrl)
        {
            // not already logged in, so continue
            Session.Clear();
            System.Threading.Thread.Sleep(250); // slight delay to deter bots

            try
            {
                var auth = new logic.Rules.Authentication(Request.GetOwinContext());
                auth.Login(auth.GetUser(txtUsername, txtPassword));
            }
            catch (Exception ex)
            {
                ViewBag.LoginErrMsg = ex.Message;
                return(View());
            }

            //returnURL needs to be decoded
            string decodedUrl = "";

            if (!string.IsNullOrEmpty(returnUrl))
            {
                decodedUrl = Server.UrlDecode(returnUrl);
            }

            //Login logic...

            if (Url.IsLocalUrl(decodedUrl))
            {
                return(Redirect(decodedUrl));
            }
            else
            {
                return(RedirectToRoute("home"));
            }
        }
Ejemplo n.º 30
0
        public ActionResult Index(int id)
        {
            var model = new bat.logic.ViewModels.Lessons.View();

            try
            {
                var user = new logic.Rules.Authentication(Request.GetOwinContext()).GetLoggedInUser();
                if (user == null)
                {
                    return(RedirectToRoute("home"));
                }

                model = _lessonsService.LoadView(id, user.ID);

                if (model.lesson.CancelledDate.HasValue)
                {
                    return(View("CancelledLesson", model));
                }

                if (logic.Helpers.WebRTC.WebRTCAvailable())
                {
                    model = _lessonsService.GenerateTokBoxToken(model, user.ID, user.Email);
                    return(View("ViewTokBox", model));
                }
                else
                {
                    return(View("WebRTCUnavailable", model));
                }

                // no longer using zoom
                //if (!model.CurrentlyAZoomUser)
                //{
                //    model.CheckZoomUser();
                //    return View("NewZoomUserAccount", model);
                //}

                //switch (model.accountType)
                //{
                //    case Types.AccountTypes.Student:
                //        if (!model.LessonReady)
                //            return View("ZoomLessonHostNotReady", model);
                //        break;

                //    case Types.AccountTypes.Teacher:
                //        model.CreateZoomMeeting();
                //        return View("ViewZoom", model);

                //    default:
                //        throw new Exception("Invalid account type.");
                //}
            }
            //catch (ZoomException ex) when (ex.Code == bat.logic.Constants.Zoom.ErrorCode_CannotCreateMeeting)
            //{
            //    return View("NewZoomUserAccount", model);
            //}
            catch (Exception ex)
            {
                ViewBag.Error = ex.Message;
                return(View("Error", model));
            }
        }