static AppController()//just for testing but later to be instances
 {
     LoginModel.AllCountries   = AppContentDB.GetCountries(Startup.StaticConfig.GetConnectionString(DEFAULT_CONNECTION));
     LoginModel.InstituteTypes = LookUpDB.GetInstituteTypes(Startup.StaticConfig.GetConnectionString(DEFAULT_CONNECTION));
     LoginModel.Curriculums    = LookUpDB.GetAllCurriculum(Startup.StaticConfig.GetConnectionString(DEFAULT_CONNECTION));
     LoginModel.Classes        = LookUpDB.GetAllClasses(Startup.StaticConfig.GetConnectionString(DEFAULT_CONNECTION));
     LoginModel.AllLanguages   = AppContentDB.GetLanguages(Startup.StaticConfig.GetConnectionString(DEFAULT_CONNECTION));
     LoginModel.Subjects       = LookUpDB.GetAllSubjects(Startup.StaticConfig.GetConnectionString(DEFAULT_CONNECTION));
     LoginModel.TutorService   = LookUpDB.GetAllTutorServices(Startup.StaticConfig.GetConnectionString(DEFAULT_CONNECTION));
 }
        public IActionResult Details(long id)
        {
            TutorModel tutorModel = base.TutorModel;

            if (tutorModel != null)
            {
                tutorModel.Languages = AppContentDB.GetLanguages(GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                return(View(tutorModel));
            }
            return(base.AssureLogin(this.CurrentController, this.CurrentAction));
        }
示例#3
0
 protected override async Task ExecuteAsync(CancellationToken stoppingToken)
 {
     while (!stoppingToken.IsCancellationRequested)
     {
         //_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
         EmailNotifier.SysRecipients = AppContentDB.GetSourceRecipients(_configuration.GetConnectionString(DEFAULT_CONNECTION));
         DataList <Notification> notifs = ScheduleDB.GetNotifications(Notification.NotificationType.Email, 0 - (short)DateTimeOffset.Now.Offset.TotalMinutes, DateTime.Now.AddMilliseconds(-DelayMS), DateTime.Now.AddMilliseconds(DelayMS), 1, _configuration.GetConnectionString(DEFAULT_CONNECTION));
         Console.WriteLine(string.Concat(notifs.Data.Count, "notifications ready to send."));
         new NotificationProcessor <Notification>(notifs.Data, this).Start();
         Console.WriteLine("Sending notifications...");
         System.GC.Collect();
         await Task.Delay(DelayMS, stoppingToken);
     }
 }
        public IActionResult Subjects(LoginModel loginModel)
        {
            TutorModel tutorModel = base.TutorModel;

            if (tutorModel != null)
            {
                try
                {
                    tutorModel.Resources = LookUpDB.GetTranslation("Pages.Subjects", 1, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                    tutorModel.Globals   = LookUpDB.GetTranslation("Global", 1, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                    tutorModel.Languages = AppContentDB.GetLanguages(GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                }
                catch (Exception ex) { /*GetLogger().Log(LogLevel.Error, ex.Message);*/ }
                return(View(tutorModel));
            }
            return(base.AssureLogin(this.CurrentController, this.CurrentAction));
        }
 public IActionResult Langs()
 {
     return(Json(AppContentDB.GetLanguages(Startup.StaticConfig.GetConnectionString(DEFAULT_CONNECTION))));
 }
示例#6
0
        public IActionResult LoginView(LoginModel model)
        {
            string conStr = GetConfiguration().GetConnectionString(DEFAULT_CONNECTION);

            if (model == null && TempData["LoginModel"] != null)
            {
                string modelStr = TempData["LoginModel"].ToString();
                model = JsonConvert.DeserializeObject <LoginModel>(modelStr);
            }
            User user = UserDB.Login(model.User.Type, model.User.Email, model.User.Password, model.User.TimezoneOffset, conStr);

            if (user != null)
            {
                if (model.Token != null)
                {
                    model.Token.Approved = true;
                }
                else
                {
                    model.Token = new AccessToken {
                        Approved = false
                    };
                }
                user.Picture = null;                                                                           //because picture is too long for the uri
                HttpContext.Response.Cookies.Append("user", JsonConvert.SerializeObject(user), cookieOptions); //new CookieOptions() { Path = "/", Domain = null, IsEssential = true });
                if (user.Type == EntityType.Tutor)
                {
                    Tutor      tutor      = (Tutor)user;
                    TutorModel tutorModel = new TutorModel {
                        User = tutor, Languages = AppContentDB.GetLanguages(conStr)
                    };
                    string tutorStr = JsonConvert.SerializeObject(tutorModel);
                    HttpContext.Response.Cookies.Append("tutor", tutorStr, cookieOptions);
                    TempData["TutorModel"] = tutorStr;
                    if (tutorModel.RedirectController != null && tutorModel.RedirectController.Length > 0)
                    {
                        string controller = tutorModel.RedirectController;
                        tutorModel.RedirectController = null;
                        if (tutorModel.RedirectAction != null && tutorModel.RedirectAction.Length > 0)
                        {
                            string action = tutorModel.RedirectAction;
                            tutorModel.RedirectAction = null;
                            return(RedirectToAction(action, controller)); //, tutorModel);
                        }
                        return(RedirectToAction(null, controller));       //, tutorModel);
                    }
                    RegistrationStep step = StepsDB.NextRegStep(user.UserId, 1, (byte)user.Type, model.Language, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                    if (step != null)
                    {
                        return(RedirectToAction(step.UIName, "Tutor"));
                    }
                }
                else if (user.Type == EntityType.Student)
                {
                    //jinan
                    Student student = (Student)user;
                    HttpContext.Session.Set("StudentId", NumberUtil.ToBytes(student.Id));
                    student.RegStepsCompleted = StepsDB.CheckCompletedSteps(user.UserId, 1, (byte)user.Type, conStr);
                    StudentModel studentModel = new StudentModel {
                        User = student, Languages = AppContentDB.GetLanguages(conStr)
                    };
                    string studentStr = JsonConvert.SerializeObject(studentModel);
                    HttpContext.Response.Cookies.Append("student", studentStr, cookieOptions);
                    TempData["StudentModel"] = studentStr;
                    if (studentModel.RedirectController != null && studentModel.RedirectController.Length > 0)
                    {
                        string controller = studentModel.RedirectController;
                        studentModel.RedirectController = null;
                        if (studentModel.RedirectAction != null && studentModel.RedirectAction.Length > 0)
                        {
                            string action = studentModel.RedirectAction;
                            studentModel.RedirectAction = null;
                            return(RedirectToAction(action, controller)); //, studentModel);
                        }
                        return(RedirectToAction(null, controller));       //, studentModel);
                    }
                    if (student.RegStepsCompleted)
                    {
                        return(RedirectToAction("DisplayDashboard", "Student"));
                    }
                }
            }
            else
            {
                ViewData["Message"] = "User Login failed !!";
                Response.StatusCode = (int)HttpStatusCode.BadRequest;
            }
            return(RedirectToAction("Index", "Home"));
        }
示例#7
0
        public IActionResult LoginSvc(string json)
        {
            //User user = JsonConvert.DeserializeObject<User>(json);
            LoginModel loginModel = JsonConvert.DeserializeObject <LoginModel>(json);

            if (loginModel != null && loginModel.User != null)
            {
                loginModel.User = UserDB.Login(loginModel.User.Type, loginModel.User.Email, loginModel.User.Password, loginModel.User.TimezoneOffset, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                if (loginModel.User == null)
                {
                    ViewData["Message"] = "User Login Details failed !!";
                    Response.StatusCode = (int)HttpStatusCode.BadRequest;
                    return(Content("Login failed!", MediaTypeNames.Text.Plain));
                }
                if (!loginModel.User.Active.HasValue || !loginModel.User.Active.Value)
                {
                    return(Unauthorized());
                }
                Response.StatusCode = (int)HttpStatusCode.OK;

                loginModel.User.Picture = null;
                //HttpContext.Response.Cookies.Append("user", JsonConvert.SerializeObject(loginModel.User), cookieOptions);
                switch (loginModel.User.Type)
                {
                case EntityType.Tutor:
                    Tutor tutor = (Tutor)loginModel.User;
                    //HttpContext.Response.Cookies.Append("user", JsonConvert.SerializeObject(loginModel.User), cookieOptions);
                    TutorModel tutorModel = new TutorModel {
                        Date               = DateTime.Now,
                        User               = tutor,
                        RedirectAction     = loginModel.RedirectAction,
                        RedirectController = loginModel.RedirectController,
                        Languages          = AppContentDB.GetLanguages(GetConfiguration().GetConnectionString(DEFAULT_CONNECTION))
                    };
                    string tutorStr = null;
                    if (tutorModel.RedirectController != null && tutorModel.RedirectController.Length > 0 || tutorModel.RedirectAction != null && tutorModel.RedirectAction.Length > 0)
                    {
                        tutorStr = JsonConvert.SerializeObject(tutorModel);
                        TempData["TutorModel"] = JsonConvert.SerializeObject(tutorModel.Tutor.Cache());
                        return(Json(tutorModel));
                    }
                    RegistrationStep step = StepsDB.NextRegStep(loginModel.User.UserId, null, (byte)loginModel.User.Type, loginModel.Language, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                    if (step != null)
                    {
                        tutorModel.RedirectAction     = step.UIName;
                        tutorModel.RedirectController = "tutor";
                        tutorModel.Tutor.CurrentStep  = step;
                    }
                    else
                    {
                        tutorModel.RedirectAction     = "details";
                        tutorModel.RedirectController = "tutor";
                        tutorModel.Tutor.CurrentStep  = step;
                    }

                    tutorStr = JsonConvert.SerializeObject(tutorModel);
                    TempData["TutorModel"] = JsonConvert.SerializeObject(tutorModel.Tutor.Cache());
                    return(Json(tutorModel));

                case EntityType.Student:
                    //jinan
                    Student student = (Student)loginModel.User;
                    //HttpContext.Session.SetString("StudentModel", JsonConvert.SerializeObject(new StudentModel { User = student }));
                    //HttpContext.Session.Set("StudentId", NumberUtil.ToBytes(student.Id));
                    //HttpContext.Response.Cookies.Append("user", JsonConvert.SerializeObject(loginModel.User), cookieOptions);
                    StudentModel studentModel = new StudentModel {
                        Date               = DateTime.Now,
                        User               = student,
                        RedirectAction     = loginModel.RedirectAction,
                        RedirectController = loginModel.RedirectController,
                        Languages          = AppContentDB.GetLanguages(GetConfiguration().GetConnectionString("DefaultConnection"))
                    };
                    string studentStr = JsonConvert.SerializeObject(studentModel.Student.Cache());
                    //HttpContext.Response.Cookies.Append("student", studentStr, cookieOptions);
                    TempData["StudentModel"] = studentStr;
                    if (studentModel.RedirectController == null || studentModel.RedirectController.Length == 0)
                    {
                        //studentModel.RedirectAction = "DashboardDisplay";
                        //studentModel.RedirectController = "Student";
                        studentModel.RedirectAction     = "StudentHome";
                        studentModel.RedirectController = "Student";
                        return(Json(studentModel));
                    }
                    return(Json(studentModel));

                case EntityType.Parent:
                    break;

                case EntityType.School:
                    break;
                }
            }
            loginModel = new LoginModel {
                Date = DateTime.Now, User = null, RedirectAction = "Index", RedirectController = "Home", Token = new AccessToken {
                    Approved = false
                }
            };
            return(Json(loginModel));
        }