public static async Task LookupAndSendAsync(SocketGuild guild, SocketCommandContext context, string channelName, string message, bool replyable, DataBase db) { var dbGuild = FindOrCreateGuild.Perform(guild, db); if (!UserHasRole.Perform(guild, context.User, dbGuild)) { await context.Channel.SendMessageAsync("You do not have the role required to send messages to this server."); return; } var candidateChannels = guild.TextChannels.Where(x => x.Name.ToLower().Contains(channelName.ToLower()) || x.Id.ToString() == channelName); if (!candidateChannels.Any()) { await context.Channel.SendMessageAsync("The channel you specified couldn't be found. Please specify your channel using the following command: `send (channel_name) (message)` ex: `send some-channel you guys suck`"); return; } var prefix = PrefixHelper.ComputePrefix(context, dbGuild); var channel = candidateChannels.OrderBy(x => x.Name.Length).First(); var messageFunction = Send.SendMessageToChannel(channel, replyable, context.User); await messageFunction(prefix, message); await Send.SendSentEmote(context); }
public Employee GetNextEmployee() { Random rand = new Random(Guid.NewGuid().GetHashCode()); int Id = EmployeeId; EmployeeId++; string Email = "Mail" + rand.Next(1000); int AccessFailedCount = 0; DateTime LockoutEndsDateTimeUTC = DateTime.Now.AddDays(-1); Address ContactAddress = GetNextAddress(); Address ResidentialAddress = GetNextAddress(); string PhoneNumber = "PhoneNumber" + rand.Next(1000); List <Password> Passwords = new List <Password>(); int r1 = rand.Next() % 5 + 1; for (int i = 0; i < r1; i++) { Passwords.Add(GetNextPassword(Id)); } List <UserHasRole> UserRoles = new List <UserHasRole>(); int r2 = rand.Next() % NumberOfRoles + 1; List <int> notThisRoleId = new List <int>(); for (int i = 0; i < r2; i++) { UserHasRole a = GetNextUserHasRole(Id, notThisRoleId); notThisRoleId.Add(a.Role.Id); UserRoles.Add(a); } string Position = "Position" + rand.Next(1000); PersonalInformation Information = GetNextPersonalInformation(); return(new Employee(Id, Email, Position, Information, AccessFailedCount, LockoutEndsDateTimeUTC, ContactAddress, ResidentialAddress, PhoneNumber, Passwords, UserRoles)); }
public async Task <IHttpActionResult> PutUserHasRole(int id, UserHasRole userHasRole) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != userHasRole.Id) { return(BadRequest()); } db.Entry(userHasRole).State = EntityState.Modified; try { await db.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UserHasRoleExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task <IHttpActionResult> GetUserHasRole(int id) { UserHasRole userHasRole = await db.UserHasRoles.FindAsync(id); if (userHasRole == null) { return(NotFound()); } return(Ok(userHasRole)); }
public async Task <IHttpActionResult> PostUserHasRole(UserHasRole userHasRole) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.UserHasRoles.Add(userHasRole); await db.SaveChangesAsync(); return(CreatedAtRoute("DefaultApi", new { id = userHasRole.Id }, userHasRole)); }
public async Task <IHttpActionResult> DeleteUserHasRole(int id) { UserHasRole userHasRole = await db.UserHasRoles.FindAsync(id); if (userHasRole == null) { return(NotFound()); } db.UserHasRoles.Remove(userHasRole); await db.SaveChangesAsync(); return(Ok(userHasRole)); }
public IndividualClient GetNextIndividualClient() { Random rand = new Random(Guid.NewGuid().GetHashCode()); int Id = IndividualClientId; IndividualClientId++; string Email = "Mail" + rand.Next(1000); int AccessFailedCount = 0; DateTime LockoutEndsDateTimeUTC = DateTime.Now.AddDays(-1); Address ContactAddress = GetNextAddress(); Address ResidentialAddress = GetNextAddress(); string PhoneNumber = "PhoneNumber" + rand.Next(1000); List <Password> Passwords = new List <Password>(); int r1 = rand.Next() % 5 + 1; for (int i = 0; i < r1; i++) { Passwords.Add(GetNextPassword(Id)); } List <UserHasRole> UserRoles = new List <UserHasRole>(); int r2 = rand.Next() % NumberOfRoles + 1; List <int> notThisRoleId = new List <int>(); for (int i = 0; i < r2; i++) { UserHasRole a = GetNextUserHasRole(Id, notThisRoleId); notThisRoleId.Add(a.Role.Id); UserRoles.Add(a); } string ContactTitle = "CT" + rand.Next(1000); List <Order.Order> Orders = new List <Order.Order>(); int r3 = rand.Next() % 5 + 1; for (int i = 0; i < r3; i++) { Orders.Add(OrderGenerator.Instatnce.GetNextOrder()); } List <CustomerDiscount> discounts = new List <CustomerDiscount>(); int r4 = rand.Next() % 5 + 1; for (int i = 0; i < r4; i++) { discounts.Add(DiscountGenerator.Intance.GetNextCustomerDiscount(Id)); } PersonalInformation Information = GetNextPersonalInformation(); return(new IndividualClient(Id, Email, AccessFailedCount, LockoutEndsDateTimeUTC, ContactAddress, ResidentialAddress, PhoneNumber, Information, ContactTitle, Passwords, UserRoles, Orders, discounts)); }
public static async Task LookupAndSendAsync(SocketGuild guild, ShardedCommandContext context, string channelName, string message, bool replyable, DataBase db) { var dbGuild = FindOrCreateGuild.Perform(guild, db); if (!UserHasRole.Perform(guild, context.User, dbGuild)) { await Send.SendErrorWithDeleteReaction(context, "You do not have the role required to send messages to this server."); return; } var candidateChannels = guild.TextChannels.Where(x => x.Name.ToLower().Contains(channelName.ToLower()) || x.Id.ToString() == channelName); if (!candidateChannels.Any()) { await Send.SendErrorWithDeleteReaction(context, "The channel you specified couldn't be found. Please specify your channel using the following command: `send (channel_name) (message)` ex: `send some-channel you guys suck`"); return; } if (PrefixHelper.UserBlocked(context.User.Id, dbGuild)) { await context.Channel.SendMessageAsync("It appears that you have been banned from using Voltaire on the targeted server. If you think this is an error, contact one of your admins."); return; } if (!IncrementAndCheckMessageLimit.Perform(dbGuild, db)) { await Send.SendErrorWithDeleteReaction(context, "This server has reached its limit of 50 messages for the month. To lift this limit, ask an admin or moderator to upgrade your server to Voltaire Pro."); return; } var prefix = PrefixHelper.ComputePrefix(context, dbGuild); var channel = candidateChannels.OrderBy(x => x.Name.Length).First(); var messageFunction = Send.SendMessageToChannel(channel, replyable, context); await messageFunction(prefix, message); await Send.SendSentEmote(context); return; }
/// <inheritdoc /> public ITypeSetExposureConfiguration Authorize(string role = null, string policy = null) { IEndPointMethodAuthorization authorization = null; if (!string.IsNullOrEmpty(policy)) { authorization = new UserHasPolicy(policy); } else if (!string.IsNullOrEmpty(role)) { authorization = new UserHasRole(role); } else { authorization = new UserIsAuthorized(); } return(Authorize(type => new[] { authorization })); }
public IExposureConfiguration Authorize(string role = null, string policy = null) { IEndPointMethodAuthorization authorization = null; if (!string.IsNullOrEmpty(policy)) { authorization = new UserHasPolicy(policy); } else if (!string.IsNullOrEmpty(role)) { authorization = new UserHasRole(role); } else { authorization = new UserIsAuthorized(); } _authorizations = _authorizations.Add(authorization); return(this); }
private static bool FilterGuildByRole(SocketGuildUser reciver, IUser sender, DataBase db) { var guild = db.Guilds.FirstOrDefault(x => x.DiscordId == reciver.Guild.Id.ToString()); return(UserHasRole.Perform(reciver.Guild, sender, guild)); }
// validate the username and password public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { var identity = new ClaimsIdentity(context.Options.AuthenticationType); // context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" }); using (var db = new TicketCenterAPI.Models.ticketcenterdbEntities1()) { if (db != null) { var usersWithRoles = db.UserHasRoles.ToList(); var user = db.Users.ToList(); if (user != null) { if (!string.IsNullOrEmpty(user.Where(u => u.Email == context.UserName && u.Password == context.Password).FirstOrDefault().Email)) { //find user fix this User loginUser = user.Where(u => u.Email == context.UserName && u.Password == context.Password).FirstOrDefault(); //add intities identity.AddClaim(new Claim("username", context.UserName)); identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName)); var clients = db.Clients.ToList(); Client client = clients.Where(x => x.UserId == loginUser.id).FirstOrDefault(); Employee emp = db.Employees.Where(e => e.UserId == loginUser.id).FirstOrDefault(); string empId; if (emp == null) { empId = ""; } else { empId = emp.Id + ""; } string clientId; //************ if user is not a client ***************** if (client == null) { clientId = ""; } else { //give me the client clientId = client.Id + ""; } string roleId; //get user role UserHasRole userRole = usersWithRoles.Where(u => u.UserId == loginUser.id).FirstOrDefault(); //********** if user is a client role id is empty if (userRole == null) { roleId = ""; } else { roleId = userRole.RoleId + ""; } var props = new AuthenticationProperties(new Dictionary <string, string> { { "Email", context.UserName }, { "aId", loginUser.id + "" }, { "FirstName", loginUser.FirstName }, { "LastName", loginUser.LastName }, { "ClientId", clientId }, { "aRoleId", roleId }, { "aEmpId", empId } }); var ticket = new AuthenticationTicket(identity, props); context.Validated(ticket); } else { context.SetError("invalid_grant", "Provided username and password is incorrect"); context.Rejected(); } } } else { context.SetError("invalid_grant", "Provided username and password is incorrect"); context.Rejected(); } return; } }