public static Models.User MapDatabaseUser(Database.User user) { return(new Models.User() { Name = user.Name, LastName = user.LastName, City = user.City, Login = user.Login, Years = user.Years, Password = user.Password }); }
protected virtual async Task <Audio.AudioRequest> GetSubscriberAudioRequest( Database.User subscriber, string message, int monthCount, int tier) { Audio.AudioRequest soundEffectRequest = null; Audio.AudioRequest ttsRequest = null; if (soundEffectSystem.HasSoundEffects()) { Audio.SoundEffect subSoundEffect = soundEffectSystem.GetSoundEffectByName("SMW PowerUp"); if (subSoundEffect is null) { communication.SendWarningMessage($"Expected Sub SoundEffect not found. Defaulting to first sound effect."); subSoundEffect = soundEffectSystem.GetSoundEffectByName(soundEffectSystem.GetSoundEffects()[0]); } soundEffectRequest = new Audio.SoundEffectRequest(subSoundEffect); } if (!string.IsNullOrWhiteSpace(message)) { ttsRequest = await ttsRenderer.TTSRequest( voicePreference : subscriber.TTSVoicePreference, pitchPreference : subscriber.TTSPitchPreference, effectsChain : audioEffectSystem.SafeParse(subscriber.TTSEffectsChain), ttsText : message); } return(JoinRequests(300, soundEffectRequest, ttsRequest)); }
public virtual async void HandleSubscription( string userId, string message, int monthCount, int tier, bool approved) { Database.User subscriber = await userHelper.GetUserByTwitchId(userId); if (subscriber == null) { communication.SendErrorMessage($"Unable to find user {userId} for Subscription handling"); return; } communication.NotifyEvent($"Tier {tier} Sub: {subscriber.TwitchUserName}"); string chatResponse = await GetSubscriberChatResponse(subscriber, message, monthCount, tier); if (!string.IsNullOrWhiteSpace(chatResponse)) { communication.SendPublicChatMessage(chatResponse); } activityDispatcher.QueueActivity( activity: new FullActivityRequest( fullActivityProvider: this, description: $"Sub: {subscriber.TwitchUserName}: {message ?? ""}", notificationMessage: await GetSubscriberNotificationRequest(subscriber, message, monthCount, tier), audioRequest: await GetSubscriberAudioRequest(subscriber, message, monthCount, tier), marqueeMessage: await GetSubscriberMarqueeMessage(subscriber, message, monthCount, tier)), approved: approved); }
public override Task Execute(Message message, TelegramBotClient client) { var chatId = message.Chat.Id; var users = db.UserStatuses.Where(s => s.Chat.ChatId == chatId).Select(s => s.User).ToList(); Database.User user = users.ElementAt(rnd.Next(0, users.Count())); var status = db.UserStatuses.FirstOrDefault(s => s.User.Id == user.Id); status.FugCount++; db.SaveChanges(); var newAchivement = Program.CheckAndAddAchivement(status); string nick = user.UserName == null ? $"<a href=\"tg://user?id={user.UserId}\">{user.FirstName}</a>" : $"@{user.UserName}"; /*if (newAchivement != null) * { * client.SendTextMessageAsync(chatId, * String.Format( * db.Phrases.ToList().ElementAt(rnd.Next(0, db.Phrases.Count())).Text, nick), ParseMode.Html); * return client.SendPhotoAsync(chatId, photo: newAchivement.PathToImage, * caption: $"<b>Вы заработали новую ачивку:</b>\n {nick}", ParseMode.Html); * } * else{*/ return(client.SendTextMessageAsync(chatId, /*String.Format(*/ /*db.Phrases.ToList().ElementAt(rnd.Next(0, db.Phrases.Count())).Text,*/ nick, ParseMode.Html)); /*}*/ }
public static User SaveUser(User userNew) { using (var context = new Database.postgresContext()) { var user = context.User.FirstOrDefault(u => u.Sub == userNew.Sub); if (user == null) { user = new Database.User(); } user.Alias = userNew.Alias; user.FirstName = userNew.FirstName; user.LastName = userNew.LastName; user.Mail = userNew.Mail; user.Sub = userNew.Sub; if (user.Id == 0) { context.User.Add(user); } context.SaveChanges(); return(ParseUser(user)); } }
public virtual async void HandleAnonGiftSub( string recipientId, int tier, int months, bool approved) { Database.User recipient = await userHelper.GetUserByTwitchId(recipientId); if (recipient == null) { communication.SendErrorMessage($"Unable to find reciever {recipientId} for Gift Sub handling"); return; } communication.NotifyEvent($"Gift Sub from Anon to {recipient.TwitchUserName}"); string chatResponse = await GetAnonGiftSubChatResponse(recipient, tier, months); if (!string.IsNullOrWhiteSpace(chatResponse)) { communication.SendPublicChatMessage(chatResponse); } activityDispatcher.QueueActivity( activity: new FullActivityRequest( fullActivityProvider: this, description: $"Anon Gift Sub To: {recipient.TwitchUserName}", notificationMessage: await GetAnonGiftSubNotificationRequest(recipient, tier, months), audioRequest: await GetAnonGiftSubAudioRequest(recipient, tier, months), marqueeMessage: await GetAnonGiftSubMarqueeMessage(recipient, tier, months)), approved: approved); }
public virtual async void HandleRaid( string raiderId, int count, bool approved) { Database.User raider = await userHelper.GetUserByTwitchId(raiderId); if (raider == null) { communication.SendErrorMessage($"Unable to find user {raiderId} for Raid handling"); return; } communication.NotifyEvent($"{count} Raid: {raider.TwitchUserName}"); string chatResponse = await GetRaidChatResponse(raider, count); if (!string.IsNullOrWhiteSpace(chatResponse)) { communication.SendPublicChatMessage(chatResponse); } activityDispatcher.QueueActivity( activity: new FullActivityRequest( fullActivityProvider: this, description: $"Raid: {raider.TwitchUserName} with {count} viewers", notificationMessage: await GetRaidNotificationRequest(raider, count), audioRequest: await GetRaidAudioRequest(raider, count), marqueeMessage: await GetRaidMarqueeMessage(raider, count)), approved: approved); }
/// <summary> /// 删除用户 /// </summary> /// <param name="userID">用户编号</param> public HttpResponseMessage Delete(int userID) { string tokenID = string.Empty; var queryString = Request.GetQueryNameValuePairs(); var token = queryString.FirstOrDefault(q => q.Key.ToLower() == "token"); if (!string.IsNullOrEmpty(token.Value)) { tokenID = token.Value; } AuthenticationFunction.TokenValidation(tokenID); if (userID == 0) { return new HttpResponseMessage(HttpStatusCode.BadRequest); } else { var user = new Database.User() { UserID = userID }; var userFunction = new UserFunction(); int error = userFunction.DeleteUser(user); var response = GetResponse.UserResponse(error); return response; } }
protected virtual Task <string> GetAnonGiftSubChatResponse( Database.User recipient, int tier, int months) { return(Task.FromResult <string>(null)); }
public virtual async void HandleFollower( Database.User follower, bool approved) { if (followedUserIds.Add(follower.TwitchUserId)) { communication.NotifyEvent($"Follow: {follower.TwitchUserName}"); } else { communication.NotifyEvent($"Re-Follow: {follower.TwitchUserName}"); //Skip notifications return; } string chatResponse = await GetFollowChatResponse(follower); if (!string.IsNullOrWhiteSpace(chatResponse)) { communication.SendPublicChatMessage(chatResponse); } activityDispatcher.QueueActivity( activity: new FullActivityRequest( fullActivityProvider: this, description: $"Follower: {follower.TwitchUserName}", notificationMessage: await GetFollowNotificationRequest(follower), audioRequest: await GetFollowAudioRequest(follower), marqueeMessage: await GetFollowMarqueeMessage(follower)), approved: approved); }
protected virtual Task <MarqueeMessage> GetAnonGiftSubMarqueeMessage( Database.User recipient, int tier, int months) { return(Task.FromResult <MarqueeMessage>(null)); }
private async Task TestCheerHandler(IRC.TwitchChatter chatter, string[] remainingCommand) { if (chatter.User.AuthorizationLevel < AuthorizationLevel.Admin) { communication.SendPublicChatMessage($"You are not authorized to test cheer notifications, @{chatter.User.TwitchUserName}."); return; } if (remainingCommand.Length < 4) { communication.SendPublicChatMessage($"@{chatter.User.TwitchUserName}, error in testing cheer notification. Syntax is !testcheer <user> <cheertype> <bits> <message>."); } else { Database.User cheerer = await userHelper.GetUserByTwitchLogin(remainingCommand[0].ToLower(), false); if (cheerer == null) { communication.SendWarningMessage($"Requested user {remainingCommand[0]} not found in database. Substituting broadcaster."); cheerer = await userHelper.GetUserByTwitchId(botConfig.BroadcasterId, false); } if (!int.TryParse(remainingCommand[2], out int quantity)) { quantity = 1000; } string message = string.Join(' ', remainingCommand[3..]) + $" {remainingCommand[1]}{remainingCommand[2]}";
private async Task TestRaidHandler(IRC.TwitchChatter chatter, string[] remainingCommand) { if (chatter.User.AuthorizationLevel < AuthorizationLevel.Admin) { communication.SendPublicChatMessage($"You are not authorized to test raid notifications, @{chatter.User.TwitchUserName}."); return; } string userId = botConfig.BroadcasterId; int userCount = 100; //Optional Raider Name if (remainingCommand.Length > 0) { Database.User raider = await userHelper.GetUserByTwitchLogin(remainingCommand[0]); if (raider is not null) { userId = raider.TwitchUserId; } } //Optional Raider Count if (remainingCommand.Length > 1 && int.TryParse(remainingCommand[1], out int newUserCount)) { userCount = newUserCount; } raidHandler.HandleRaid(userId, userCount, true); return; }
protected virtual Task <NotificationMessage> GetFollowNotificationRequest(Database.User follower) { return(Task.FromResult <NotificationMessage>(new ImageNotificationMessage( image: notificationServer.GetNextImageURL(), duration: 4_000, message: GetFollowNotificationMessage(follower)))); }
public ActionResult Login(Login login, string returnUrl) { Database.User user = Database.User.Get(login.UserName, login.Password); login.Valid = user != null; if (login.Valid) { LoginUser = user.Name; UserID = user.UserID.ToString(); if (string.IsNullOrEmpty(returnUrl)) { return(RedirectToAction("AllTickets", "Ticket")); } else { return(Redirect(returnUrl)); } } else { ModelState.AddModelError("Username", "Incorrect credentials."); return(View()); } }
public static User SaveUser(string sub, string alias, string mail, string first_name, string last_name) { using (var context = new Database.postgresContext()) { var user = context.User.FirstOrDefault(u => u.Sub == sub); if (user == null) { user = new Database.User(); } user.Alias = alias; user.FirstName = first_name; user.LastName = last_name; user.Mail = mail; user.Sub = sub; if (user.Id == 0) { context.User.Add(user); } context.SaveChanges(); return(ParseUser(user)); } }
protected virtual async Task <Audio.AudioRequest> GetCheerAudioRequest( Database.User cheerer, string message, int quantity) { Audio.AudioRequest soundEffectRequest = null; Audio.AudioRequest ttsRequest = null; if (soundEffectSystem.HasSoundEffects()) { Audio.SoundEffect cheerSoundEffect = soundEffectSystem.GetSoundEffectByName("FF7 Purchase"); if (cheerSoundEffect is null) { communication.SendWarningMessage($"Expected Cheer SoundEffect not found. Defaulting to first"); cheerSoundEffect = soundEffectSystem.GetSoundEffectByName(soundEffectSystem.GetSoundEffects()[0]); } soundEffectRequest = new Audio.SoundEffectRequest(cheerSoundEffect); } if (!string.IsNullOrWhiteSpace(message)) { ttsRequest = await ttsRenderer.TTSRequest( voicePreference : cheerer.TTSVoicePreference, pitchPreference : cheerer.TTSPitchPreference, effectsChain : audioEffectSystem.SafeParse(cheerer.TTSEffectsChain), ttsText : message); } return(JoinRequests(300, soundEffectRequest, ttsRequest)); }
protected virtual Task <string> GetCheerChatResponse( Database.User cheerer, string message, int quantity) { return(Task.FromResult <string>(null)); }
/// <summary> /// Clone constructor /// </summary> /// <param name="parent">The instance to clone</param> public ListUserEntry(Database.User parent) { foreach (var f in typeof(Database.User).GetFields()) { f.SetValue(this, f.GetValue(parent)); } this.Password = null; }
public Result Index(string nickname, string number, string email, string firstName, string lastName, string position, string password, string specialty, string group) { var result = new Result(); try { using (var db = new DatabaseContext()) { var user = new Database.User(); user.Nickname = nickname; user.FirstName = firstName; user.LastName = lastName; user.Number = number; user.PasswordHash = password.GetSHA256(); user.UserId = db.Users.Count() + 1; user.Token = user.PasswordHash.GetSHA256() + new Random().Next(1, 999999999); user.Friends = ""; user.FirendsRequests = ""; user.PathProfilePic = "avatars/Stock/usr.jpg"; user.FriendsRequested = ""; user.Status = "online"; user.Group = ""; user.Position = position; user.Specialty = specialty; user.Group = group; user.Specialty = ""; user.AccessLevel = 1; user.EMail = email; db.Users.Add(user); db.UnreadMessages.Add(new UnreadMessages() { Messages = "", UserId = user.UserId }); db.SaveChanges(); var response = new Shared.Models.Register(); response.Token = user.Token; response.UserId = user.UserId; result.Data = response; result.Status = true; } } catch (Exception e) { var error = new Error(); error.Code = 1; error.Message = "Неизвестная ошибка"; result.Data = error; result.Status = false; return(result); } return(result); }
protected virtual Task <NotificationMessage> GetRaidNotificationRequest( Database.User raider, int count) { return(Task.FromResult <NotificationMessage>(new ImageNotificationMessage( image: notificationServer.GetNextImageURL(), duration: 10_000, message: $"WOW! {count} raiders incoming from {HttpUtility.HtmlEncode(raider.TwitchUserName)}!"))); }
protected virtual Task <Audio.AudioRequest> GetTTSAudioRequest( Database.User user, string message) { return(ttsRenderer.TTSRequest( voicePreference: user.TTSVoicePreference, pitchPreference: user.TTSPitchPreference, effectsChain: audioEffectSystem.SafeParse(user.TTSEffectsChain), ttsText: message)); }
protected virtual Task <NotificationMessage> GetAnonGiftSubNotificationRequest( Database.User recipient, int tier, int months) { return(Task.FromResult <NotificationMessage>(new ImageNotificationMessage( image: notificationServer.GetNextImageURL(), duration: 5_000, message: GetAnonGiftSubNotificationMessage(recipient, tier, months)))); }
protected virtual async Task <NotificationMessage> GetCheerNotificationRequest( Database.User cheerer, string message, int quantity) { return(new ImageNotificationMessage( image: await cheerHelper.GetCheerImageURL(message, quantity), duration: 10_000, message: GetCheerMessage(cheerer, message, quantity))); }
protected virtual string GetFollowNotificationMessage(Database.User follower) { string fontColor = follower.Color; if (string.IsNullOrWhiteSpace(fontColor)) { fontColor = "#0000FF"; } return($"Thanks for the following, <span style=\"color: {fontColor}\">{HttpUtility.HtmlEncode(follower.TwitchUserName)}</span>!"); }
public Data registerPlayer(Client client, Database.User data) { Data player = new Data(client, data); playersDict.Add(client.Handle, player); LoadPlayerCharacters(player); player.InitAuth(data.id); return(player); }
public void GetUser_user_should_be_call() { // Arrange string email = "*****@*****.**"; //Act Database.User result = userService.GetUser(email); //Assert mockUserRepository.Verify(c => c.GetAll()); }
protected virtual Task <NotificationMessage> GetSubscriberNotificationRequest( Database.User subscriber, string message, int monthCount, int tier) { return(Task.FromResult <NotificationMessage>(new ImageNotificationMessage( image: notificationServer.GetNextImageURL(), duration: 5000, message: GetSubscriberNotificationMessage(subscriber, message, monthCount, tier)))); }
public async Task <IResult> Request( [Parameter(ParameterSource.Form)] string email ) { if (string.IsNullOrWhiteSpace(email)) { return(Status(BadRequest, "Missing email field")); } // Try to not leak information about existence of email address await Task.Delay(TimeSpan.FromMilliseconds(new Random().Next(600, 1500))); Database.User user = null; var rr = await DB.RunInTransactionAsync(db => { // TODO: Abort if we have multiple accounts with the same email user = db.SelectSingle <Database.User>(x => string.Equals(x.Email, email, StringComparison.OrdinalIgnoreCase)); if (user != null) { var resetreq = db.SelectSingle <Database.ResetPasswordRequest>(x => x.UserID == user.ID); if (resetreq != null) { if ((DateTime.Now - resetreq.Created) > TimeSpan.FromDays(1)) { resetreq.Created = DateTime.Now; resetreq.Token = Services.PasswordPolicy.GenerateActivationCode(); db.UpdateItem(resetreq); return(resetreq); } } else { db.InsertItem(resetreq = new Database.ResetPasswordRequest() { UserID = user.ID, Token = Services.PasswordPolicy.GenerateActivationCode() }); return(resetreq); } } return(null); }); if (user != null && rr != null) { await Queues.SendPasswordResetEmailAsync(user.Name, user.Email, rr.ID, Services.LocaleHelper.GetBestLocale(Ceen.Context.Request)); } return(OK); }
protected void btnSubmit_Click(object sender, EventArgs e) { try { string username = txtUserName.Text; var users = context.Users.Where(x => x.IsActive == true && x.UserName == username); if (users.Count() > 0) { lblMessage.Text = "User Already exist with same username"; lblMessage.ForeColor = Color.Red; } else { Database.User user = new Database.User(); if (ddlRole.SelectedValue != "0" && ddlEmployee.SelectedValue != "0") { user.CreatedBy = currentUserName; user.CreatedDate = DateTime.Now; user.IsActive = true; user.Password = txtPassword.Text; user.UserName = txtUserName.Text; user.UserRoleTypeID = Convert.ToInt32(ddlRole.SelectedValue); user.EmployeeID = Convert.ToInt32(ddlEmployee.SelectedValue); user.IsActive = true; user.Remarks = txtRemarks.Text; context.Users.Add(user); context.SaveChanges(); if (CheckInternet()) { sendEmail(Convert.ToInt32(ddlEmployee.SelectedValue), user); //Success message is set from email method } else { lblMessage.Text = "User Created But Email is not sent due to no internet"; lblMessage.ForeColor = Color.Green; } ClearForm(); } else { lblMessage.Text = "Please Select Employee and Role"; lblMessage.ForeColor = Color.Red; } } } catch (Exception ex) { Helper.LogError(ex); lblMessage.Text = "Something went Wrong kindly check log"; lblMessage.ForeColor = Color.Red; } }
protected virtual Task <MarqueeMessage> GetCheerMarqueeMessage( Database.User cheerer, string message, int quantity) { if (string.IsNullOrWhiteSpace(message)) { return(Task.FromResult <MarqueeMessage>(null)); } return(Task.FromResult(new MarqueeMessage(cheerer.TwitchUserName, message, cheerer.Color))); }
//用户登录验证和发放令牌 public static int UserLogon(string userName, string password, out string tokenID, out UserViewResult logonUser) { tokenID = string.Empty; logonUser = new UserViewResult(); Database.User entity = new Database.User() { UserName = userName, Password = password }; UserFunction userFunction = new UserFunction(); int error = userFunction.CheckUser(entity, out logonUser); if (error != 0) { return error; } else { tokenID = AuthenticationFunction.CreateTokenID(logonUser); var newToken = new Token() { TokenID = tokenID, UserID = logonUser.UserID, ExpiredTime = DateTime.Now.AddMinutes(60) }; TokenFunction tokenFunction = new TokenFunction(); tokenFunction.AddToken(newToken); return 0; } }