// GET: Teacher public ActionResult Index() { TeacherIndexViewModel vm = new TeacherIndexViewModel(); LogiraniKorisnikVM k = Autentifikacija.GetLogiraniKorisnik(HttpContext); vm.username = k.username; vm.Name = k.Ime + ' ' + k.Prezime; vm.QuizSessions = db.QuizSessions.Include(x => x.Quiz).Where(x => x.UserId == k.Id).Select(y => new TeacherIndexViewModel.QuizSessionInfo { Id = y.Id, QuizName = y.Quiz.Name, QuizvId = y.Quiz.vId, StartDate = y.StartedAt.Value, ResultPercentage = ((int)(((float)y.CorrectAnswers) / (y.CorrectAnswers + y.WrongAnswers) * 100)).ToString() + "%", QuizDuration = DbFunctions.DiffMinutes(y.StartedAt, y.FinishedAt).ToString() }).OrderByDescending(x => x.StartDate).ToList(); vm.AvailableQuizes = db.Quizes.Select(x => new TeacherIndexViewModel.QuizInfo { vId = x.vId, CreatedAt = x.CreatedAt, CreatedBy = x.Teacher.Name, Name = x.Name, QuestionCount = x.Questions.Count }).ToList(); return(View(vm)); }
public void OnAuthorization(AuthorizationContext filterContext) { LogiraniKorisnikVM k = Autentifikacija.GetLogiraniKorisnik(filterContext.HttpContext); if (k == null) { filterContext.HttpContext.Response.Redirect("/"); } }
public static void PokreniNovuSesiju(LogiraniKorisnikVM korisnik, HttpContextBase context, bool zapamtiPassword) { context.Session.Add(LogiraniKorisnik, korisnik); if (zapamtiPassword) { HttpCookie cookie = new HttpCookie("_mvc_session", korisnik != null ? korisnik.Id.ToString() : ""); cookie.Expires = DateTime.Now.AddDays(30); context.Response.Cookies.Add(cookie); } }
public static bool Login(string username, string password, HttpContextBase httpContext) { using (Context ctx = new Context()) { var user = ctx.Users.FirstOrDefault(x => x.username == username); if (user != null) { if (Crypto.VerifyHashedPassword(user.passwordHash, password + user.passwordSalt)) { LogiraniKorisnikVM k = new LogiraniKorisnikVM(); k.Id = user.Id; k.username = user.username; PokreniNovuSesiju(k, httpContext, true); return(true); } } } return(false); }
public static LogiraniKorisnikVM GetLogiraniKorisnik(HttpContextBase context) { LogiraniKorisnikVM korisnik = (LogiraniKorisnikVM)context.Session[LogiraniKorisnik]; return(korisnik); }