public IActionResult Preferences()
        {
            TutorModel tutorModel = base.TutorModel;

            if (tutorModel != null)
            {
                if (Request.QueryString != null && Request.QueryString.HasValue)
                {
                    long userId  = Request.Query["user"].Equals(string.Empty) ? 0 : long.Parse(Request.Query["user"]);
                    long tutorId = Request.Query["tutor"].Equals(string.Empty) ? 0 : long.Parse(Request.Query["tutor"]);
                    if (userId > 0 && tutorId > 0)
                    {
                        bool             isTeacher = bool.Parse(Request.Query["alreadyTeacher"]);
                        TutorPreferences pref      = new TutorPreferences
                        {
                            TutorId                = tutorId,
                            IsTeacher              = isTeacher,
                            TeachingInstitute      = isTeacher ? Request.Query["school"].ToString() : null,
                            HasCertification       = isTeacher && Request.Query["hasCert"].Equals(string.Empty) ? false : bool.Parse(Request.Query["hasCert"]),
                            YearsOfExperience      = isTeacher ? Request.Query["yearsOfExperience"].Equals(string.Empty) ? 0 : int.Parse(Request.Query["yearsOfExperience"]) : 0,
                            TutoringTypes          = Request.Query["typeOfStudents"],
                            LessonTypes            = Request.Query["lessonTypes"],
                            RewardingPoints        = Request.Query["rewardings"],
                            HasCar                 = bool.Parse(Request.Query["alreadyTeacher"]),
                            IsInterested           = bool.Parse(Request.Query["onlineTutoringInterest"]),
                            OutsideTutoringWeekHrs = Request.Query["hrsOutsideINTO"].Equals(string.Empty) ? 0 : int.Parse(Request.Query["hrsOutsideINTO"]),
                            Language               = int.Parse(Request.Query["lang"]),
                            StepId                 = int.Parse(Request.Query["step"]),
                            EntityType             = (EntityType)byte.Parse(Request.Query["entityType"])
                        };
                        int rows = TutorDB.SavePreferences(pref, userId, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                        if (rows > 0)
                        {
                            RegistrationStep step = StepsDB.NextRegStep(userId, pref.StepId, (byte)pref.EntityType, pref.Language, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                            if (step != null)
                            {
                                return(RedirectToAction(step.UIName, "Tutor"));
                            }
                        }
                    }
                }
                try
                {
                    tutorModel.Resources       = LookUpDB.GetTranslation("Pages.Preferences", 1, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                    tutorModel.Globals         = LookUpDB.GetTranslation("Global", 1, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                    tutorModel.TutoringTypes   = LookUpDB.GetLookupDetails(15, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                    tutorModel.LessonTypes     = LookUpDB.GetLookupDetails(16, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                    tutorModel.RewardingPoints = LookUpDB.GetLookupDetails(17, 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 EmailConfirmation(int userId, int objEntityId, int step, int?lang = 1)
        {
            TutorModel tutorModel = base.TutorModel;

            if (tutorModel != null)
            {
                if (tutorModel.Tutor.AgreedOnTerms)
                {
                    string actUrl = string.Concat(BaseUrl, Url.Action(nameof(ReadyForInterview), "Tutor"));
                    Tutor  tutor  = TutorDB.PrepareForConfirmation(tutorModel.Tutor.UserId, (byte)tutorModel.Tutor.Type, step, actUrl, lang, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                    tutorModel.Tutor        = tutor;
                    tutorModel.contentStep6 = (LookUpDB.GetAppContent("100017,100018", 1, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION)));
                    return(View(tutorModel));
                }
                RegistrationStep regStep = StepsDB.NextRegStep(tutorModel.User.UserId, null, (byte)tutorModel.User.Type, tutorModel.Language, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION));
                if (regStep != null)
                {
                    tutorModel.Tutor.CurrentStep = regStep;
                    TempData["TutorModel"]       = JsonConvert.SerializeObject(tutorModel.Tutor.Cache());
                    return(RedirectToAction(regStep.UIName, "tutor"));
                }
            }
            return(base.AssureLogin(this.CurrentController, this.CurrentAction));
        }
 public IActionResult NextStep(long uId = 0, int stepId = 0, byte?objEntityId = 0, int?lang = null)
 {
     return(Json(StepsDB.NextRegStep(uId, stepId, objEntityId, lang, GetConfiguration().GetConnectionString(DEFAULT_CONNECTION))));
 }
示例#4
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"));
        }
示例#5
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));
        }