public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { // Attempt to register the user MembershipCreateStatus createStatus; MembershipPerson usr = MembershipService.CreateUser(model.UserName, model.Password, model.Email, model.Name, model.Gender, out createStatus) as MembershipPerson; #region DEBUG #if DEBUG // usr.Photos.Add(new Entities.Photo()); // usr.Photos[0].PhotoStream = new byte[] { 1, 2, 3 }; // usr.Photos[0].UserID = (int)usr.ProviderUserKey; #endif #endregion MembershipService.UpdateUser(usr); if (createStatus == MembershipCreateStatus.Success) { Session["CurrentUser"] = MembershipService.GetUser(model.UserName); FormsService.SignIn(model.UserName, false /* createPersistentCookie */); return(RedirectToAction("Index", "Home")); } ModelState.AddModelError("", ErrorCodeToString(createStatus)); } // If we got this far, something failed, redisplay form return(View(model)); }
public bool ValidatePerson(byte[] photo, out MembershipPerson person, ImageProcessing.support.Algorithm algorithm, out double runTime) { if (photo == null) { throw new ArgumentException("Value cannot be null or empty.", "photo"); } return((_provider as CustomMembershipProvider).ValidatePerson(photo, out person, algorithm, out runTime)); }
/// <summary> /// Update details of the authenticated user /// </summary> /// <returns></returns> public ActionResult AddNewPerson() { if (!Request.IsAuthenticated) { return(RedirectToAction("LogOnByUserName", "Account")); } Session["ComparedPhoto"] = null; Session["PersonForReview"] = new MembershipPerson("CustomMembershipProvider", new User(), string.Empty, string.Empty, true, false, DateTime.MinValue, DateTime.MinValue, DateTime.MinValue, DateTime.Now, DateTime.Now); InformationReview(); return(View("InformationReview")); }
public ActionResult SearchByPhoto(PeopleSearchModel model, string returnUrl) { if (!Request.IsAuthenticated) { return(RedirectToAction("LogOnByUserName", "Account")); } Session["ComparedPhoto"] = null; byte[] userPhoto = (byte[])Session["ContentStream"]; double runTime = -1; try { if (Request.Form["Algorithm"] == null) { throw new Exception(); } support.Algorithm alg = support.Algorithm.EigenFaces; if (!Enum.TryParse <support.Algorithm>(Request.Form["Algorithm"].ToString(), out alg)) { throw new Exception(); } AccountMembershipService service = new AccountMembershipService(); MembershipPerson person = null; if (service.ValidatePerson(userPhoto, out person, alg, out runTime)) { Session["LastRecognitionAlgorithm"] = Enum.GetName(typeof(support.Algorithm), alg); Session["LastRecognitionTime"] = runTime; if (person != null) { Session["PersonForReview"] = person; Session["ComparedPhoto"] = userPhoto; return(View("PersonSearch")); } } } catch { } finally { // Session["ContentStream"] = null; // Session["ContentLength"] = null; // Session["ContentType"] = null; } ModelState.AddModelError("", "No record found."); return(View("PersonSearch")); }
public ActionResult InformationUpdate(UpdateUserModel model, string returnUrl) { if ((Session["PersonForReview"] != null) && (Session["PersonForReview"].GetType() == typeof(MembershipPerson))) { MembershipPerson person = Session["PersonForReview"] as MembershipPerson; person.person.Gender = model.Gender; person.person.Name = model.Name; if ((Session["PersonForReview"] as MembershipPerson).person.PersonID != 0) { // usr.Avatar = Session["ContentStream"] == null ? null : (Session["ContentStream"] as byte[]); MembershipService.UpdateUser(Session["PersonForReview"] as MembershipPerson); } else if ((Session["PersonForReview"] as MembershipPerson).person.PersonID == 0) { MembershipService.CreatePerson(Session["PersonForReview"] as MembershipPerson); } return(View("../Home/InformationReview", model)); } return(null); }
public JsonNetResult GetQueries() { byte result = 1; string msg = null; List <dynamic> queries = new List <dynamic>(); try { string sql = "SELECT q.id, q.name, q.conn, q.grp, q.drv, q.usercreate authorid FROM qb_vqueries q"; if (User.IsInRole("READER") || User.IsInRole("EDITOR") || User.IsInRole("ERASER")) { MembershipPerson mp = (MembershipPerson)HttpContext.Cache[User.Identity.Name]; if (mp != null) { sql += " WHERE q.conn IN ('" + string.Join("', '", mp.Bases.Select(b => b.Conn)) + "')"; } } else { sql += " WHERE q.usercreate = @0"; } sql += " ORDER BY q.name"; queries = db.Fetch <dynamic>(sql, User.Id); System.Diagnostics.Debug.WriteLine(db.LastSQL); } catch (Exception e) { msg = e.Message; result = 0; } JsonNetResult jr = new JsonNetResult(); jr.Data = new { success = result, message = msg, data = queries }; return(jr); }
public ActionResult AddPhoto(object model, string returnUrl) { if ((Session["PersonForReview"] != null) && (Session["ContentStream"] != null) && (Session["PersonForReview"].GetType() == typeof(MembershipPerson)) && (Session["ContentStream"].GetType() == typeof(byte[]))) { MembershipPerson usr = Session["PersonForReview"] as MembershipPerson; usr.person.Photos.Add(new Photo()); //to grayscale IplImage img = support.ByteArrayToIplImage((byte[])Session["ContentStream"], OpenCvSharp.LoadMode.GrayScale); img = ((OpenCvSharp.CPlusPlus.Mat)Cv.EncodeImage(".jpg", img)).ToIplImage(); usr.person.Photos[usr.person.Photos.Count - 1].PhotoStream = support.IplImageToByteArray(img); usr.person.Photos[usr.person.Photos.Count - 1].PersonID = (int)usr.person.PersonID; (new AccountMembershipService()).UpdateUser(usr); Session["ContentStream"] = null; Session["ContentLength"] = null; Session["ContentType"] = null; Cv.ReleaseImage(img); } return(View("PhotosManager", model)); }
public ActionResult SearchByPersonID() { if (!Request.IsAuthenticated) { return(RedirectToAction("LogOnByUserName", "Account")); } Session["ContentStream"] = null; Session["ContentLength"] = null; Session["ContentType"] = null; Session["ComparedPhoto"] = null; int personID = 0; if (int.TryParse(Request.Form["PersonID"].ToString(), out personID)) { MembershipPerson person = (new AccountMembershipService()).GetPerson(personID) as MembershipPerson; if (person != null) { Session["PersonForReview"] = person; return(View("InformationReview")); } } ModelState.AddModelError("", "No record found."); return(View("PersonSearch")); }
public MembershipUser CreatePerson(MembershipPerson person) { MembershipUser usr = (_provider as CustomMembershipProvider).CreatePerson(person); return(usr); }
protected void Application_AuthenticateRequest(Object sender, EventArgs e) { HttpCookie authCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null && !string.IsNullOrEmpty(authCookie.Value)) { FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value); if (ticket != null && !ticket.Expired) { string[] tokens = ticket.Name.Split(':'); if (tokens.Length == 2) { string login = tokens[0], passwd = tokens[1]; MembershipPerson mp = (MembershipPerson)HttpContext.Current.Cache[login]; // logged via auth cookie if (mp == null) { // update authcookie & cache if (Membership.ValidateUser(login, passwd)) { mp = (MembershipPerson)Membership.GetUser(login); if (mp.IsApproved) { HttpContext.Current.Cache.Add(login, mp, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 20, 0), CacheItemPriority.Normal, new CacheItemRemovedCallback(RemoveCallback)); FormsAuthentication.SetAuthCookie(login + ":" + passwd, ticket.IsPersistent); ThreadContext.Properties["user"] = mp.UserName; ThreadContext.Properties["host"] = Request.IsLocal ? "127.0.0.1" : Request.UserHostAddress; log.Info("Вход в систему."); } else { FormsAuthentication.SignOut(); } } else { FormsAuthentication.SignOut(); } } MemberPrincipal user = null; // valid user if (mp != null) { user = new MemberPrincipal(login); user.Id = (int)mp.ProviderUserKey; user.IsAdmin = mp.IsAdmin; user.Lastname = mp.Lastname; user.Firstname = mp.Firstname; user.Middlename = mp.Middlename; user.Fio = mp.Fio; user.ServerLogin = mp.ServerLogin; user.Theme = mp.Theme; if (user.ServerLogin == 1) { user.Schema = mp.Schema; } } HttpContext.Current.User = user; } } } }
public JsonNetResult LogOn(LogOnModel model) { byte result = 0; string msg = null; int id = 0; int isAdmin = 0; int serverLogin = 0; string fio = null; string schema = null; string[] roles = null; if (ModelState.IsValid) { try { // xor decode char[] buff = model.Password.ToCharArray(); for (int i = 0; i < model.Password.Length; ++i) { buff[i] = (char)(model.Password[i] ^ 128); } model.Password = new string(buff); if (Membership.ValidateUser(model.Login, model.Password)) { MembershipPerson mp = (MembershipPerson)Membership.GetUser(model.Login); HttpContext.Cache.Add(model.Login, mp, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 20, 0), CacheItemPriority.Normal, new CacheItemRemovedCallback(MvcApplication.RemoveCallback)); FormsAuthentication.SetAuthCookie(model.Login + ":" + model.Password, model.RememberMe); id = (int)mp.ProviderUserKey; isAdmin = mp.IsAdmin; serverLogin = mp.ServerLogin; fio = mp.Fio; schema = mp.Schema; if (mp.Roles != null) { roles = mp.Roles.ToArray(); } result = 1; ThreadContext.Properties["user"] = mp.UserName; ThreadContext.Properties["host"] = Request.IsLocal ? "127.0.0.1" : Request.UserHostAddress; log.Info("Вход в систему."); } else { msg = "Неверные логин или пароль!"; } } catch (Exception e) { msg = e.Message; } } else { msg = string.Join("<br>", ModelState.Values.SelectMany(x => x.Errors).Select(x => x.ErrorMessage)); } JsonNetResult jr = new JsonNetResult(); jr.Data = new { success = result, message = msg, id = id, fio = fio, isadmin = isAdmin, serverlogin = serverLogin, schema = schema, roles = roles }; return(jr); }