public Login CreateLogin(IInput input) { var type = input.Get<string>(Login.PropertyTypeIdentifier); if (string.IsNullOrEmpty(type) || string.Compare(type, JanRainLogin.JanRainTypeIdentifier, true) != 0) return null; return new JanRainLogin { UserName = input.Get<string>("username"), Email = input.Get<string>("email"), }; }
public bool ValidateLogin(IInput input, Login login) { var type = input.Get<string>(Login.PropertyTypeIdentifier); if (string.IsNullOrEmpty(type) || string.Compare(type, JanRainLogin.JanRainTypeIdentifier, true) != 0) return false; if (!(login is JanRainLogin)) return false; var jrLogin = login as JanRainLogin; return jrLogin.UserName == input.Get<string>("username"); }
public bool ValidateLogin(IInput input, Login login) { var type = input.Get<string>(Login.PropertyTypeIdentifier); if (string.IsNullOrEmpty(type) || string.Compare(type, FacebookLogin.FacebookTypeIdentifier, true) != 0) return false; if (string.IsNullOrEmpty(input.Get<string>("username")) || !(login is FacebookLogin)) return false; var client = new FacebookClient(input.Get<string>("access_token")); dynamic me = client.Get("me", new {fields = "id"}); return me.id == input.Get<string>("username"); }
protected override void Apply() { var filename = _input.Get("Filename"); var image = _repository.Load(filename); Canvas.Paint(image.Cells.Where(c => c.Pos < Canvas.Size)); }
protected override void ExecuteOverride(IInput input, IConnection connection, ResponseMessage response) { if (connection.User == null) { response.Invalidate(CommonResources.LoginRequired); return; } var username = input.Get<string>("username"); var login = connection.User.Logins.FirstOrDefault(l => l.UserName.ToLower() == username); if (login != null) { response.Invalidate(CommonResources.LoginAlreadyExists); return; } if (!Game.Current.Users.TryCreateLogin(input, out login)) { response.Invalidate(CommonResources.LoginAlreadyExists); return; } connection.User.Logins.Add(login); Game.Current.Repository.SaveUser(connection.User); }
public void OnLoginSuccess(User user, Login login, IInput input) { var fbLogin = login as FacebookLogin; if (fbLogin == null) return; fbLogin.AccessToken = input.Get<string>("access_token"); }
public bool Execute() { var filename = _input.Get("Filename"); _repository.Save(filename, _image); _input.Respond("File saved!"); return(true); }
public void Execute() { _output.Set("Enter a number between 1 and 4000: "); var input = _input.Get(); var workflow = _workflowFactory.Create(input); var result = _exceptionHandler.Handle(workflow); _output.Set(result); }
public ITreeNode Parse(Grammer grammer, IInput input, IGrammerRuleHandler ruleHandler) { States states = States.BuildStates(grammer); input.Parse(); Stack stack = new Stack(); TreeNodeStack treeNodeStack = new TreeNodeStack(); ruleHandler.TreeNodeStack = treeNodeStack; IAction action = states.GetAction(stack.Top(), input.Get()); while(!action.GetType().Equals(typeof(Accept))){ action.Do(input,stack,ruleHandler); action = states.GetAction(stack.Top(),input.Get()); } return treeNodeStack.Pop(); }
public Login CreateLogin(IInput input) { var username = input.Get<string>("username"); var password = input.Get<string>("password"); var email = input.Get<string>("email"); if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) return null; var pwdSalt = Cryptography.CreateSalt(); var hashedPwd = Cryptography.ComputeHash(password, pwdSalt); return new GenericLogin { UserName = username, Password = hashedPwd, PasswordSalt = pwdSalt, Email = email }; }
protected override void ExecuteOverride(IInput input, IConnection connection, ResponseMessage response) { var commandName = input.Get<string>("command"); var cmd = Game.Current.Commands.FindCommandInternal(commandName); if (cmd == null) { response.Invalidate(CommonResources.HelpNotFoundFormat, commandName); return; } connection.Write(NotificationMessage.Heading(CommonResources.HelpName), NotificationMessage.Normal(cmd.Metadata.Name)); connection.Write(NotificationMessage.Heading(CommonResources.HelpDescription), NotificationMessage.Normal(cmd.Metadata.Description)); connection.Write(NotificationMessage.Heading(CommonResources.HelpSynopsis), NotificationMessage.Normal(cmd.Metadata.Synopsis)); connection.Write(NotificationMessage.Heading(CommonResources.HelpAliases), NotificationMessage.Normal(string.Join(",", cmd.Metadata.Aliases))); }
public void OnLoginSuccess(User user, IInput input) { var username = input.Get<string>("username"); if (string.IsNullOrEmpty(username)) return; var login = user.Logins.FirstOrDefault(l => l.UserName.ToLower() == username.ToLower()); if (login == null) return; var validator = LoginValidators.FirstOrDefault(v => v.CanValidateLogin(login)); if (validator != null) validator.OnLoginSuccess(user, login, input); login.DateLastLogin = DateTime.UtcNow; Game.Current.Repository.SaveUser(user); }
public bool ValidateLogin(IInput input, Login login) { var password = input.Get<string>("password"); if (!string.IsNullOrEmpty(password)) { var genLogin = login as GenericLogin; if (genLogin != null) { var hashedPwd = Cryptography.ComputeHash(password, genLogin.PasswordSalt); if (hashedPwd == genLogin.Password) { // Valid login. return true; } } } return false; }
public Login CreateLogin(IInput input) { var type = input.Get<string>(Login.PropertyTypeIdentifier); if (string.IsNullOrEmpty(type) || string.Compare(type, FacebookLogin.FacebookTypeIdentifier, true) != 0) return null; return new FacebookLogin { UserName = input.Get<string>("username"), FirstName = input.Get<string>("first_name"), LastName = input.Get<string>("last_name"), Gender = input.Get<string>("gender"), AccessToken = input.Get<string>("access_token"), TypeIdentifier = type }; }
public bool TryGetUser(IInput input, out User user) { var username = input.Get<string>("username"); if (string.IsNullOrEmpty(username)) { user = null; return false; } user = Game.Current.Repository.GetUser(username); if (user != null) { var login = user.Logins.FirstOrDefault(l => l.UserName.ToLower() == username.ToLower()); if (login != null) { return (from validator in LoginValidators where validator.CanValidateLogin(login) select validator.ValidateLogin(input, login)).FirstOrDefault(); } } return false; }
protected override void ExecuteOverride(IInput input, IConnection connection, ResponseMessage response) { CreateType createType; if (!Enum.TryParse(input.Get<string>("type"), true, out createType)) { response.Invalidate(CommonResources.CreateCommandInvalidTypeArg); return; } var type = typeof(GameObject); switch (createType) { case CreateType.Item: type = typeof(Item); break; case CreateType.Place: type = typeof(Place); break; case CreateType.Mobile: type = typeof(Mobile); break; case CreateType.Character: type = typeof(Character); break; } IGameObject obj; string errorMessage; if (!Game.Current.TryCreateObject(type, input, out errorMessage, out obj)) { response.Invalidate(errorMessage); return; } response.Data = obj; }
public void Send(IInput input, bool active) { IOutput thisOutput = this; output.Get(thisOutput, active); }
// Helpers protected T Get <T>(IInput <T> input) { return(input.Get(this)); }