Esempio n. 1
0
        private void Checkin(FaceIDEntities db, int class_id, string code, double latitude, double longitude, string email, double accuracy)
        {
            var model = db.CheckIns.SingleOrDefault(c => c.Class_id == class_id && c.Code == code);

            if (model == null)
            {
                model = new CheckIn
                {
                    date      = DateTime.Now,
                    Class_id  = class_id,
                    Code      = code,
                    Latitude  = latitude,
                    Longitude = longitude,
                    Email     = email,
                    Accuracy  = accuracy
                };
                db.CheckIns.Add(model);
            }
            else
            {
                model.date            = DateTime.Now;
                model.Latitude        = model.Latitude;
                model.Longitude       = model.Longitude;
                model.Email           = email;
                model.Accuracy        = model.Accuracy;
                db.Entry(model).State = EntityState.Modified;
            }
        }
Esempio n. 2
0
        public async Task <ActionResult> ExternalLoginCallback(string returnUrl, string dummyEmail)
        {
            var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

            loginInfo = loginInfo ?? Session["ExternalLoginInfo"] as ExternalLoginInfo;
            if (loginInfo == null)
            {
                if (dummyEmail != null)
                {
                    using (var db = new FaceIDEntities())
                    {
                        var user  = db.AspNetUsers.Single(u => u.Email == dummyEmail);
                        var login = db.AspNetUserLogins.First(l => l.UserId == user.Id);
                        loginInfo = new ExternalLoginInfo
                        {
                            Email           = dummyEmail,
                            DefaultUserName = dummyEmail.Split('@')[0],
                            Login           = new UserLoginInfo(login.LoginProvider, login.ProviderKey)
                        };
                    }
                }
                else
                {
                    return(RedirectToAction("Login"));
                }
            }

            // Sign in the user with this external login provider if the user already has a login
            var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent : true);

            switch (result)
            {
            case SignInStatus.Success:
                var cookie = new HttpCookie("fIDLoginInfo")
                {
                    Path    = "/",
                    Expires = DateTime.Now.AddDays(365)
                };
                cookie.Values["UserEmail"]     = loginInfo.Email;
                cookie.Values["LoginProvider"] = loginInfo.Login.LoginProvider;
                cookie.Values["ProviderKey"]   = loginInfo.Login.ProviderKey;
                Response.SetCookie(cookie);
                return(RedirectToLocal(returnUrl));

            case SignInStatus.LockedOut:
                return(View("Lockout"));

            case SignInStatus.RequiresVerification:
                return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false }));

            case SignInStatus.Failure:
            default:
                // If the user does not have an account, then prompt the user to create an account
                // ViewBag.ReturnUrl = returnUrl;
                // ViewBag.LoginProvider = loginInfo.Login.LoginProvider;
                // return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = loginInfo.Email });
                return(await ExternalLoginConfirmation(new ExternalLoginConfirmationViewModel { Email = loginInfo.Email }, returnUrl));
            }
        }
Esempio n. 3
0
 public ViewResult Display(int id)
 {
     using (var db = new FaceIDEntities())
     {
         var myClass = db.MyClasses.Find(id);
         ViewBag.MyClass = myClass;
         myClass.MyTag   = db.MyTags.Find(myClass.Tag_id);
         return(View(myClass.CheckIns.ToList()));
     }
 }
Esempio n. 4
0
        public ViewResult Browser(string id)
        {
            var email = User.Identity.Name;
            var code  = email.Split('@').First().Split('.').Last();

            using (var db = new FaceIDEntities())
            {
                var model = db.CheckIns.Where(c => c.Code == code || (id == "all" && c.Email == email))
                            .Include(c => c.MyClass).Include(c => c.MyClass.MyTag);
                return(View(model.ToList()));
            }
        }
Esempio n. 5
0
 public string Upload(string code, string email, HttpPostedFileBase face, CheckIn model, string users, string accuracy)
 {
     try
     {
         code  = code.Split('-')[0];
         email = User.Identity.Name;
         using (var db = new FaceIDEntities())
         //using (var scope = new TransactionScope())
         {
             var @class = db.MyClasses.Find(int.Parse(code));
             if (@class == null)
             {
                 throw new Exception("Class doesn't exist");
             }
             if (Distance(@class.Latitude, @class.Longitude, model.Latitude, model.Longitude) > 1)
             {
                 throw new Exception("You are not in class");
             }
             var path = "~/App_Data/Checks/";
             Directory.CreateDirectory(Path.Combine(Server.MapPath(path), code));
             var faces     = users.Split(',');
             var distances = accuracy.Split(',').Select(d => double.Parse(d)).ToArray();
             for (int i = 0; i < faces.Length; i++)
             {
                 Checkin(db, int.Parse(code), faces[i], model.Latitude, model.Longitude, email, distances[i]);
                 face.SaveAs(Path.Combine(Server.MapPath(path), code, faces[i] + ".jpg"));
                 GlobalHost.ConnectionManager.GetHubContext <CheckHub>().Clients.All.addNewCheckToPage(code, faces[i]);
             }
             db.SaveChanges();
             //scope.Complete();
             return(String.Format("Check in successfully @ {0} - {1}", @class.MyTag.Name, @class.Title));
         }
     } catch (Exception e)
     {
         return("KO:" + e.GetBaseException().Message);
     }
 }