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; }
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; }
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 }); }
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; }
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 }); }
protected bool IsAuthenticated(User user) { if (Request.Cookies["AuthID"] != null) { var authId = Request.Cookies["AuthID"].Value; if (authId == user.AuthID) { return true; } } return false; }