public ActionResult Index(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return(View("Welcome"));
            }
            var user = RavenService.GetUser(RavenSession, name);

            if (user == null)
            {
                return(View("NewUser", new User {
                    UserName = name
                }));
            }
            var isAuthenticated = IsAuthenticated(user);

            if (user.IsPublic || isAuthenticated)
            {
                var challenges = RavenService.GetAllChallenges(RavenSession);
                var history    = RavenService.GetHistory(RavenSession, user);
                Thread.CurrentThread.CurrentCulture = new CultureInfo("sv-SE");
                var boardViewModel = new BoardViewModel
                {
                    Challenges      = challenges.Where(m => m.Hide == false).ToList(),
                    TotalPoints     = CalculatePoints(challenges, user),
                    CurrentUser     = user,
                    IsAuthenticated = isAuthenticated,
                    History         = history
                };
                return(View("Index", boardViewModel));
            }
            return(RedirectToAction("Index", "Authentication", new { name = user.UserName }));
        }
Exemplo n.º 2
0
        //
        // GET: /Admin/

        public ActionResult Index()
        {
            //get all challenges from database
            var model = new List <Challenge>();

            model = RavenService.GetAllChallenges(RavenSession);
            return(View(model));
        }
        public static IConfiguration ConfigureDatabase(this IConfiguration configuration)
        {
            string urlDatabase  = configuration["Database:Url"];
            string databaseName = configuration["Database:Name"];

            string[] urls = { urlDatabase };
            RavenService.CreateStore(urls, databaseName);

            return(configuration);
        }
 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 }));
 }
        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 }));
        }
Exemplo n.º 6
0
        public ActionResult Count()
        {
            //get all users
            var users      = RavenService.GetAllUsers(RavenSession);
            var challenges = RavenService.GetAllChallenges(RavenSession);

            var model = new List <Count>();

            // foreach
            foreach (var user in users)
            {
                var count = new Count()
                {
                    Name   = user.Name + "(" + user.UserName + ")",
                    Points = CalculatePoints(challenges, user)
                };

                model.Add(count);
            }
            //get all activities for user

            return(View(model));
        }
Exemplo n.º 7
0
        public ActionResult AddChallenge(Challenge challenge)
        {
            RavenService.SaveChallenge(RavenSession, challenge);

            return(RedirectToAction("AddChallenge"));
        }