Esempio n. 1
0
        public IEnumerable <StudentPoco> Course(string token, string id)
        {
            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");
            var decodedToken = PearsonApiUtilities.DecodeFrom64(token);

            Mapper.CreateMap <Student, StudentPoco>();

            var context = new StudentContext();

            var students = (from s in context.Students
                            where s.CourseIds.Every(id)
                            select s).ToList();

            foreach (var student in students)
            {
                try
                {
                    var userJson = PearsonApiUtilities.GetUserJson(decodedToken, student.StudentId);
                    var users    = new JavaScriptSerializer().Deserialize <Users>(userJson);

                    student.FirstName = users.users[0].firstName;
                    student.LastName  = users.users[0].lastName;
                }
                catch (Exception)
                {
                    //skip it... HACK
                }
            }

            var result = Mapper.Map <List <Student>, IEnumerable <StudentPoco> >(students);

            return(result);
        }
Esempio n. 2
0
        // GET /api/students/5
        public string GetStudent(string token, string id)
        {
            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");

            var decodedToken = PearsonApiUtilities.DecodeFrom64(token);

            return(PearsonApiUtilities.GetUserJson(decodedToken, id));
        }
Esempio n. 3
0
        // POST /api/signin
        //[AllowCrossSiteJson]
        public SigninResult Authenticate(string username, string password)
        {
            HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*");

            var test  = Request.Content.Headers.ToString();
            var token = PearsonApiUtilities.GetOauthAccessToken(username, password);

            //return token;

            string[] tokenParts = token.Split('|');

            var userID = tokenParts[2];

            var userJson = PearsonApiUtilities.GetUserJson(token, userID);

            var result = new SigninResult()
            {
                EncodedAuthToken = PearsonApiUtilities.EncodeTo64(token),
                UserId           = userID,
                User             = userJson
            };

            return(result);
        }