コード例 #1
0
        private int CalculatePoints(List<Challenge> challenges, User user)
        {
            var points = 0;
            foreach (Challenge challenge in challenges)
            {
                if (challenge.IsComplete(user))
                {
                    var count = challenge.NumberOfCompletions(user);
                    points += challenge.Points * count;
                }
            }

            return points;
        }
コード例 #2
0
        public static User CreateUser(IDocumentSession session, User newUser)
        {
            var user = new User {
                UserName = newUser.UserName.ToLower(),
                Name = newUser.Name,
                Password = newUser.Password,
                IsPublic = newUser.IsPublic,
                AuthID = Guid.NewGuid().ToString()
            };

            session.Store(user);
            session.SaveChanges();

            return user;
        }
コード例 #3
0
        public ActionResult Login(User user)
        {
            
            var userFromDatabase = RavenService.GetUser(RavenSession, user.UserName);
            if (user.Password != userFromDatabase.Password)
            {
                return RedirectToAction("Index", new { name = user.UserName });
            }

            
            var cookie = new HttpCookie("AuthID");
            cookie.Value = userFromDatabase.AuthID;
            cookie.Expires = new DateTime(2020, 12, 31);
            Response.Cookies.Add(cookie);
            

            return RedirectToAction("Index", "Home", new { name = user.UserName });
        }
コード例 #4
0
        public static List<FeedViewModel> GetHistory(IDocumentSession session, User user)
        {
            var list = new List<FeedViewModel>();
            var userId = "users/" + user.UserName;
            var feedItems = session.Query<Feed>().Where(m => m.UserId == userId).OrderByDescending(m => m.TimeStamp).Take(10);

            foreach (Feed feedItem in feedItems)
            {
                var model = new FeedViewModel()
                {
                    TimeStamp = feedItem.TimeStamp,
                    Challenge = GetChallengeName(session, feedItem.ChallengeId)
                };

                list.Add(model);
            }

            return list;
        }
コード例 #5
0
 public ActionResult NewUser(User user)
 {
     if (!string.IsNullOrEmpty(user.Name) && !string.IsNullOrEmpty(user.Password))
     {
         var newUser = RavenService.CreateUser(RavenSession, user);
         var cookie = new HttpCookie("AuthID");
         cookie.Value = newUser.AuthID;
         cookie.Expires = new DateTime(2020, 12, 31);
         Response.Cookies.Add(cookie);
     }
     return RedirectToAction("Index", new { name = user.UserName });
 }
コード例 #6
0
 protected bool IsAuthenticated(User user)
 {
     if (Request.Cookies["AuthID"] != null)
     {
         var authId = Request.Cookies["AuthID"].Value;
         if (authId == user.AuthID)
         {
             return true;
         }
     }
     return false;
 }