Exemple #1
0
        public IActionResult SignIn(string email)
        {
            if (HttpContext.Session.GetString("email") != null)
            {
                return(RedirectToAction("Index", "Calendar"));
            }
            if (email == null || email == "")
            {
                return(RedirectToAction("SignInEmail", "Home"));
            }
            var exists = (from c in _context.Users where c.Id == email select c).FirstOrDefault();

            if (exists == null)
            {
                Users user = new Users
                {
                    Id = email
                };
                _context.Users.Add(user);
            }

            DateTime       expireTime    = DateTime.Now.Add(new TimeSpan(0, 1, 0, 0, 0));
            String         key           = TokenGenerator.Generate(50, false);
            String         code          = TokenGenerator.Generate(6, true);
            Usersigninkeys userSigninKey = new Usersigninkeys
            {
                Userid    = email,
                Signinkey = key,
                Expire    = expireTime,
                Code      = code
            };

            _context.Usersigninkeys.Add(userSigninKey);
            _context.SaveChanges();
            ViewData["email"] = email;
            ViewData["key"]   = key;
            ViewData["code"]  = code;
            return(View());
        }
Exemple #2
0
        public IActionResult MeetingsJSON()
        {
            var email = HttpContext.Session.GetString("email");

            if (email == null)
            {
                return(Json(new { status = "invalid" }));
            }
            var now         = DateTime.Now;
            var oldMeetings = (from c in _context.Meetings where c.Starttime < now && c.Userid == email select c).ToArray();

            if (oldMeetings != null)
            {
                for (int i = 0; i < oldMeetings.Length; ++i)
                {
                    _context.Meetings.Remove(oldMeetings[i]);
                }
                _context.SaveChanges();
            }
            var meetings = (from c in _context.Meetings where c.Starttime >= now && c.Userid == email select c).Take(15).ToArray();

            return(Json(new
            {
                status = "success",
                data = meetings.Select(
                    item => new
                {
                    id = item.Id,
                    description = item.Description,
                    userid = email,
                    starttime = item.Starttime.ToString("yyyy-MM-dd HH:mm:ss"),
                    endtime = item.Endtime.ToString("yyyy-MM-dd HH:mm:ss"),
                    requestuserid = item.Requestuserid
                }
                    )
            }));
        }