Example #1
0
        public static bool Authenticate(User user)
        {
            MongoDatabaseService db = null;
            User entity = null;
            bool authorized = false;

            if (!String.IsNullOrWhiteSpace(user.email) && !String.IsNullOrWhiteSpace(user.userid))
            {
                db = new MongoDatabaseService();
                entity = db.Retrieve<User>(new QueryDocument("userid", user.userid)).FirstOrDefault();

                if (entity != null)
                {
                    authorized = true;
                }
                else
                {
                    // create user account
                    if (db.Create<User>(user) != null)
                    {
                        authorized = true;
                    }
                }
            }

            return authorized;
        }
Example #2
0
        public ActionResult Authenticate(User user)
        {
            bool authorized = OnePlant.Models.User.Authenticate(user);
            User result = null;

            if (authorized)
            {
                result = MongoDatabaseService.Retrieve<User>(new QueryDocument("email", user.email)).FirstOrDefault();
                FormsAuthentication.SetAuthCookie(user.email, true);
            }

            return Json(new { success = authorized, user = result });
        }
Example #3
0
 public ActionResult Delete(User user)
 {
     User existingUser = getUser(user.email);
     if (existingUser == null)
     {
         return Json(new ArgumentException());
     }
     else
     {
         try
         {
             var deleted = MongoDatabaseService.Delete<User>(user.email);
             return Json(deleted);
         }
         catch (Exception emAll)
         {
             return Json(emAll);
         }
     }
 }
Example #4
0
        public ActionResult Create(User user)
        {
            User existingUser = getUser(user.email);
            if (existingUser == null)
            {
                //new user
                try
                {
                    user = MongoDatabaseService.Create<User>(user);
                }
                catch (Exception emAll)
                {
                    return Json(emAll);
                }
            }
            else
            {
                //user already exists
                user = existingUser;
            }

            return Json(user);
        }
Example #5
0
        public ActionResult PeopleLeaderboard()
        {
            List<User> people = new List<User>();
            var model = new User
            {
                firstName = "Jack",
                lastName = "Matthews",
                points = 200
            };
            people.Add(model);

            model = new User
            {
                firstName = "Rob",
                lastName = "Johnson",
                points = 80
            };
            people.Add(model);

            model = new User
            {
                firstName = "Diveo",
                lastName = "Hawaii",
                points = 230
            };
            people.Add(model);

            model = new User
            {
                firstName = "Eric",
                lastName = "Cantona",
                points = 290
            };
            people.Add(model);

            return Json(people.OrderByDescending(i => i.points), JsonRequestBehavior.AllowGet);
        }
Example #6
0
 public ActionResult Update(User user)
 {
     try
     {
         bool updated = MongoDatabaseService.Update<User>(user);
         return Json(updated);
     }
     catch (Exception emAll)
     {
         return Json(emAll);
     }
 }