public JsonResult EditPassword(string oldPass, string newPass) { TypeValidator v = TypeValidator.Validator; UserData user = (UserData)this.Session["user"]; // check if the user is not blocked from password related actions if (!UserManager.Manager.isUserAllowed(user.Email)) { return(Json(new { Success = false, ErrMsg = "החשבון הנ\"ל חסום מפעולות למשך 5 דקות." }, JsonRequestBehavior.AllowGet)); } // check the passwords for type if (v.Validate(oldPass, "Password") && v.Validate(newPass, "Password")) { UserData passTest = UserManager.Manager.GetIfCorrect(user.Email, oldPass); if (passTest != null && passTest.Id == user.Id) { // the old password is correct Dictionary <string, string> newValues = new Dictionary <string, string>(); newValues["password"] = newPass; bool isSuccess = UserManager.Manager.Change(user.Id, newValues); return(Json(new { Success = isSuccess, ErrMsg = "שגיאה בשרת." }, JsonRequestBehavior.AllowGet)); } else { // the old password is NOT correct int badAttempts = UserManager.Manager.addIncorrectAttempt(user.Email); bool isBlocked = !UserManager.Manager.isUserAllowed(user.Email); if (!isBlocked) { // user is still not blocked return(Json(new { Success = false, ErrMsg = "הסיסמה הישנה שהזנת אינה נכונה. נותרו " + (3 - badAttempts) + " מס' הזנות לא נכונות של הסיסמה עד לחסימה" }, JsonRequestBehavior.AllowGet)); } else { // user got blocked this.Session["user"] = null; } return(Json(new { Success = false, ErrMsg = "החשבון נחסם למשך 5 דקות" }, JsonRequestBehavior.AllowGet)); } } return(Json(new { Success = false, ErrMsg = "אחת הסיסמאות שהזנן אינה בםורמט הנכון." }, JsonRequestBehavior.AllowGet)); }
private bool IsValidUser(UserModel user, Result result, bool updating = false) { if (TypeValidator.Validate(user) == FlowOptions.Failed) { result.AddMessageToList(UserResource.NotValid); } else { if (updating && TypeValidator.Validate(user.Uid) == FlowOptions.Failed) { result.AddMessageToList(UserResource.UidRequired); } if (TypeValidator.Validate(user.DisplayName) == FlowOptions.Failed) { result.AddMessageToList(UserResource.NameRequired); } if (TypeValidator.Validate(user.Email) == FlowOptions.Failed) { result.AddMessageToList(UserResource.EmailRequired); } if (TypeValidator.Validate(user.RoleId) == FlowOptions.Failed) { result.AddMessageToList(UserResource.RoleRequired); } } return((result.Messages.Count() == 0) ? true : false); }
public void Validate_Get_expr_yields_no_error_for_defined_variable() { // Arrange // // This is the method being referred to. The expression below roughly matches "Foo.to_string", where // Foo is a defined Perlang class. var name = new Token(TokenType.IDENTIFIER, "to_string", null, -1); var identifier = new Expr.Identifier(name); var getExpr = new Expr.Get(identifier, name); var bindings = new Dictionary <Expr, Binding> { { identifier, new ClassBinding(identifier, new PerlangClass("Foo", new List <Stmt.Function>())) } }; var typeValidationErrors = new List <TypeValidationError>(); var warnings = new List <CompilerWarning>(); // Act TypeValidator.Validate( new List <Stmt> { new Stmt.ExpressionStmt(getExpr) }, error => typeValidationErrors.Add(error), expr => bindings[expr], warning => warnings.Add(warning) ); // Assert Assert.Empty(typeValidationErrors); Assert.Empty(warnings); }
public void Validate_Get_expr_yields_expected_error_for_undefined_variable() { // Arrange var name = new Token(TokenType.IDENTIFIER, "foo", null, -1); var identifier = new Expr.Identifier(name); var getExpr = new Expr.Get(identifier, name); var bindings = new Dictionary <Expr, Binding> { // A null TypeReference here is the condition that is expected to lead to an "undefined variable" error. { identifier, new VariableBinding(typeReference: null, 0, identifier) } }; var typeValidationErrors = new List <TypeValidationError>(); var warnings = new List <CompilerWarning>(); // Act TypeValidator.Validate( new List <Stmt> { new Stmt.ExpressionStmt(getExpr) }, error => typeValidationErrors.Add(error), expr => bindings[expr], warning => warnings.Add(warning) ); // Assert Assert.Single(typeValidationErrors); Assert.Matches(typeValidationErrors.Single().Message, "Undefined identifier 'foo'"); Assert.Empty(warnings); }
public void Validate_Call_expr_does_something_useful() { // Arrange var name = new Token(TokenType.IDENTIFIER, "to_string", null, 1); var identifier = new Expr.Identifier(name); var get = new Expr.Get(identifier, name); var paren = new Token(TokenType.RIGHT_PAREN, ")", null, 1); var callExpr = new Expr.Call(get, paren, new List <Expr>()); var bindings = new Dictionary <Expr, Binding> { { identifier, new NativeClassBinding(identifier, typeof(string)) } }; var typeValidationErrors = new List <TypeValidationError>(); var warnings = new List <CompilerWarning>(); // Act TypeValidator.Validate( new List <Stmt> { new Stmt.ExpressionStmt(callExpr) }, error => typeValidationErrors.Add(error), expr => bindings[expr], warning => warnings.Add(warning) ); // Assert Assert.Empty(typeValidationErrors); Assert.Empty(warnings); }
private bool IsValidHotel(HotelModel hotel, Result result) { if (TypeValidator.Validate(hotel) == FlowOptions.Failed) { result.AddMessageToList(HotelResource.NotValid); } else { if (TypeValidator.Validate(hotel.Name) == FlowOptions.Failed) { result.AddMessageToList(HotelResource.NameRequired); } if (TypeValidator.Validate(hotel.IdCity) == FlowOptions.Failed) { result.AddMessageToList(HotelResource.CityRequired); } if (TypeValidator.Validate(hotel.Address) == FlowOptions.Failed) { result.AddMessageToList(HotelResource.AddressRequired); } if (TypeValidator.Validate(hotel.Stars) == FlowOptions.Failed) { result.AddMessageToList(HotelResource.StarsRequired); } if (TypeValidator.Validate(hotel.Tax) == FlowOptions.Failed) { result.AddMessageToList(HotelResource.TaxRequired); } } return((result.Messages.Count() == 0) ? true : false); }
private bool IsValidRoom(RoomModel room, Result result) { if (TypeValidator.Validate(room) == FlowOptions.Failed) { result.AddMessageToList(RoomResources.NotValid); } else { if (TypeValidator.Validate(room.IdHotel) == FlowOptions.Failed) { result.AddMessageToList(RoomResources.HotelRequired); } if (TypeValidator.Validate(room.Code) == FlowOptions.Failed) { result.AddMessageToList(RoomResources.CodeRequired); } if (TypeValidator.Validate(room.Guests) == FlowOptions.Failed) { result.AddMessageToList(RoomResources.GuestsRequired); } if (TypeValidator.Validate(room.Price) == FlowOptions.Failed) { result.AddMessageToList(RoomResources.PriceRequired); } if (TypeValidator.Validate(room.Tax) == FlowOptions.Failed) { result.AddMessageToList(RoomResources.TaxRequired); } } return((result.Messages.Count() == 0) ? true : false); }
public JsonResult Login(string email, string password) { TypeValidator v = TypeValidator.Validator; // validate the expected type of the login fields if (!v.Validate(email, "Email") || !v.Validate(password, "Letters")) { return(Json(new { Success = false, ErrMsg = "פורמט שדות שגוי" }, JsonRequestBehavior.AllowGet)); } UserData user = UserManager.Manager.GetIfCorrect(email, password); // check is user is allowed if (!UserManager.Manager.isUserAllowed(email)) { return(Json(new { Success = false, ErrMsg = "החשבון הנ\"ל חסום מפעולות למשך 5 דקות." }, JsonRequestBehavior.AllowGet)); } Session["user"] = user; if (user == null) { // loging credentials are incorrect int badAttempts = UserManager.Manager.addIncorrectAttempt(email); bool isBlocked = !UserManager.Manager.isUserAllowed(email); if (!isBlocked) { // user is still not blocked return(Json(new { Success = false, ErrMsg = "הסיסמה שהזנת אינה נכונה. נותרו " + (3 - badAttempts) + " מס' הזנות לא נכונות של הסיסמה עד לחסימה" }, JsonRequestBehavior.AllowGet)); } else { // user got blocked this.Session["user"] = null; } return(Json(new { Success = false, ErrMsg = "החשבון נחסם למשך 5 דקות" }, JsonRequestBehavior.AllowGet)); } return(Json(new { Success = true }, JsonRequestBehavior.AllowGet)); }
private bool IsValidBooking(BookingModel booking, Result result) { if (TypeValidator.Validate(booking) == FlowOptions.Failed) { result.AddMessageToList(BookingResource.NotValidBooking); } else { if (booking.StartDate >= booking.EndDate) { result.AddMessageToList(BookingResource.DatesNotValid); } if (TypeValidator.Validate(booking.IdHotel) == FlowOptions.Failed) { result.AddMessageToList(BookingResource.HotelRequired); } if (TypeValidator.Validate(booking.IdRoom) == FlowOptions.Failed) { result.AddMessageToList(BookingResource.RoomRequired); } if (TypeValidator.Validate(booking.ApplicantName) == FlowOptions.Failed) { result.AddMessageToList(BookingResource.ApplicantRequired); } if (TypeValidator.Validate(booking.Email) == FlowOptions.Failed) { result.AddMessageToList(BookingResource.EmailRequired); } if (TypeValidator.Validate(booking.ContactName) == FlowOptions.Failed) { result.AddMessageToList(BookingResource.ContactNameRequired); } if (TypeValidator.Validate(booking.ContactPhone) == FlowOptions.Failed) { result.AddMessageToList(BookingResource.ContactPhoneRequired); } foreach (GuestModel guest in booking.Guests) { if (TypeValidator.Validate(guest) == FlowOptions.Failed) { result.AddMessageToList(BookingResource.NotValidGuest); } else { if (TypeValidator.Validate(guest.Name) == FlowOptions.Failed) { result.AddMessageToList(BookingResource.GuestNameRequired); } if (TypeValidator.Validate(guest.LastName) == FlowOptions.Failed) { result.AddMessageToList(BookingResource.GuestLastNRequired); } if (TypeValidator.Validate(guest.BirtDate) == FlowOptions.Failed) { result.AddMessageToList(BookingResource.GuestBirtRequired); } if (TypeValidator.Validate(guest.Name) == FlowOptions.Failed) { result.AddMessageToList(BookingResource.GuestNameRequired); } if (TypeValidator.Validate(guest.LastName) == FlowOptions.Failed) { result.AddMessageToList(BookingResource.GuestLastNRequired); } if (TypeValidator.Validate(guest.BirtDate) == FlowOptions.Failed) { result.AddMessageToList(BookingResource.GuestBirtRequired); } if (TypeValidator.Validate(guest.Genre) == FlowOptions.Failed) { result.AddMessageToList(BookingResource.GuestGenreRequired); } if (TypeValidator.Validate(guest.Identification) == FlowOptions.Failed) { result.AddMessageToList(BookingResource.GuestIdRequired); } if (TypeValidator.Validate(guest.IdentificationType) == FlowOptions.Failed) { result.AddMessageToList(BookingResource.GuestIdTypeRequired); } if (TypeValidator.Validate(guest.Email) == FlowOptions.Failed) { result.AddMessageToList(BookingResource.GuesEmailRequired); } if (TypeValidator.Validate(guest.PhoneNumber) == FlowOptions.Failed) { result.AddMessageToList(BookingResource.GuestPhoneRequired); } } } } return((result.Messages.Count == 0) ? true : false); }
public JsonResult EditPersonalInfo(string password, string fname, string lname, string email, string office, string phone, string cellPhone) { TypeValidator v = TypeValidator.Validator; UserData user = (UserData)this.Session["user"]; // check if the user is not blocked from password related actions if (!UserManager.Manager.isUserAllowed(user.Email)) { return(Json(new { Success = false, ErrMsg = "החשבון הנ\"ל חסום מפעולות למשך 5 דקות." }, JsonRequestBehavior.AllowGet)); } // validate the fields for type if (v.Validate(password, "Password") && v.Validate(fname, "Letters") && v.Validate(lname, "Letters") && v.Validate(email, "Email") && v.Validate(office, "Integer") && v.Validate(phone, "Phone") && v.Validate(cellPhone, "Phone")) { UserData passTest = UserManager.Manager.GetIfCorrect(user.Email, password); if (passTest != null && passTest.Id == user.Id) { // the old password is correct Dictionary <string, string> newValues = new Dictionary <string, string>(); newValues["fname"] = fname; newValues["lname"] = lname; newValues["email"] = email; newValues["office"] = office; newValues["cell_phone"] = cellPhone; newValues["phone"] = phone; bool isSuccess = UserManager.Manager.Change(user.Id, newValues); if (isSuccess) { // update the user in the Session this.Session["user"] = UserManager.Manager.GetIfCorrect(email, password); } return(Json(new { Success = isSuccess, ErrMsg = "שגיאה בשרת." }, JsonRequestBehavior.AllowGet)); } else { // the old password is in-correct int badAttempts = UserManager.Manager.addIncorrectAttempt(user.Email); bool isBlocked = !UserManager.Manager.isUserAllowed(user.Email); this.Session["user"] = null; if (!isBlocked) { // user is still not blocked return(Json(new { Success = false, ErrMsg = "הסיסמה הישנה שהזנת אינה נכונה. נותרו " + (3 - badAttempts) + " מס' הזנות לא נכונות של הסיסמה עד לחסימה" }, JsonRequestBehavior.AllowGet)); } else { // user got blocked return(Json(new { Success = false, ErrMsg = "החשבון נחסם למשך 5 דקות" }, JsonRequestBehavior.AllowGet)); } } } return(Json(new { Success = false, ErrMsg = "אחד מהשדות שהזנן אינו בפורנט הנכון." }, JsonRequestBehavior.AllowGet)); }