Ejemplo n.º 1
0
        public ActionResult Login()
        {
            if (HttpContext.User.Identity.Name != "")
            {
                int userId = Convert.ToInt32(HttpContext.User.Identity.Name);


                UserTypeResponse userTypeResponse = TheDataStore.getUserType(userId);

                if (userTypeResponse.response.isOk)
                {
                    switch (userTypeResponse.type)
                    {
                    case UserType.teacher:
                        return(RedirectToAction("Teacher"));

                    case UserType.student:
                        return(RedirectToAction("Student"));
                    }
                    ;
                }
            }


            LoginPageModelResponse pageModelResponse = TheDataStore.FetchLoginPageModel();

            LoginPageModel pageModel = pageModelResponse.pageModel;

            return(View(pageModel));
        }
Ejemplo n.º 2
0
        public HttpResponseMessage unsubscribe(UnsubscribeCO cO)
        {
            int userId = Convert.ToInt32(HttpContext.Current.User.Identity.Name);

            Response response = TheDataStore.unsubscribeToClassRoom(userId, cO.classRoomName);

            return(TheDataStore.makeHttpResponseMessage(response, cO.requestObject, Request, userId));
        }
Ejemplo n.º 3
0
        public HttpResponseMessage changeDoneState(ChangeDoneStateCO cO)
        {
            int userId = Convert.ToInt32(HttpContext.Current.User.Identity.Name);

            Response response = TheDataStore.changeDoneState(cO.assignmentId, cO.currentDoneState, userId);

            return(TheDataStore.makeHttpResponseMessage(response, cO.requestObject, Request, userId));
        }
Ejemplo n.º 4
0
        public HttpResponseMessage edit(EditAssignmentCO cO)
        {
            int userId = Convert.ToInt32(HttpContext.Current.User.Identity.Name);

            Response response = TheDataStore.editAssignment(cO.id, cO.newName, cO.newDueDateTicks, cO.newDescription, cO.newArchiveStatus);

            return(TheDataStore.makeHttpResponseMessage(response, cO.requestObject, Request, userId));
        }
Ejemplo n.º 5
0
        public HttpResponseMessage create(CreateAssignmentCO cO)
        {
            int userId = Convert.ToInt32(HttpContext.Current.User.Identity.Name);

            Response response = TheDataStore.createAssignment(cO.newName, cO.classRoomName, cO.newDueDateTicks, cO.newDescription);

            return(TheDataStore.makeHttpResponseMessage(response, cO.requestObject, Request, userId));
        }
Ejemplo n.º 6
0
        public HttpResponseMessage archive(ArchiveClassRoomCO cO)
        {
            int userId = Convert.ToInt32(HttpContext.Current.User.Identity.Name);

            Response response = TheDataStore.changeClassRoomArchiveStatus(cO.classRoomName, cO.newArchiveStatus);


            return(TheDataStore.makeHttpResponseMessage(response, cO.requestObject, Request, userId));
        }
Ejemplo n.º 7
0
        public ActionResult Student()
        {
            int userId = Convert.ToInt32(HttpContext.User.Identity.Name);

            StudentPageModelResponse response = TheDataStore.FetchStudent(userId);

            StudentPageModel pageModel = response.pageModel;

            return(View(pageModel));
        }
Ejemplo n.º 8
0
        public HttpResponseMessage register(RegisterUserCO cO)
        {
            UserResponse userResponse = TheDataStore.registerNewUser(cO);

            if (!userResponse.response.isOk)
            {
                return(Request.CreateErrorResponse(System.Net.HttpStatusCode.InternalServerError, userResponse.response.message));
            }
            else
            {
                return(Request.CreateResponse(System.Net.HttpStatusCode.OK, "success"));
            }
        }
Ejemplo n.º 9
0
        public HttpResponseMessage get(string classRoomName)
        {
            int userId = Convert.ToInt32(HttpContext.Current.User.Identity.Name);

            DataResponse dataResponse = TheDataStore.getData(new SubRequest(RequestType.studentClassRoom, classRoomName, -1), userId);

            if (!dataResponse.response.isOk)
            {
                return(Request.CreateErrorResponse(System.Net.HttpStatusCode.InternalServerError, dataResponse.response.message));
            }
            else
            {
                return(Request.CreateResponse(System.Net.HttpStatusCode.OK, dataResponse.responseObject));
            }
        }
Ejemplo n.º 10
0
        public HttpResponseMessage attemptLogin(string email, string passwordAttempt)
        {
            LoginResponse loginResponse = TheDataStore.attemptLogin(email, passwordAttempt);

            if (!loginResponse.response.isOk)
            {
                return(Request.CreateErrorResponse(System.Net.HttpStatusCode.InternalServerError, loginResponse.response.message));
            }
            else
            {
                if (loginResponse.success)
                {
                    string idString = loginResponse.userId.ToString();


                    //FormsAuthentication.SetAuthCookie(idString, false);



                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                        1,                                                                   // version
                        idString,                                                            // get username  from the form
                        DateTime.Now,                                                        // issue time is now
                        DateTime.Now.AddMinutes(60 * 24 * 7),                                // expires in
                        true,                                                                // cookie is persists ovr sessions
                        ((loginResponse.userType == UserType.teacher)?"Teacher" : "Student") // role assignment is stored in userData
                        );



                    HttpCookie cookie = new HttpCookie(
                        FormsAuthentication.FormsCookieName,
                        FormsAuthentication.Encrypt(ticket)
                        );


                    HttpContext.Current.Response.Cookies.Add(cookie);

                    //Request.Headers.Add("Set-Cookie", cookie.ToString());
                }


                return(Request.CreateResponse(System.Net.HttpStatusCode.OK, loginResponse));
            }
        }