public async Task <IActionResult> CreateChannel([FromForm] CreateChannelAddressModel model) { var token = await _dbContext.AccessTokens.Include(t => t.ApplyApp).SingleOrDefaultAsync(t => t.Value == model.AccessToken); if (token == null || token.ApplyApp == null) { return(Protocal(ErrorType.Unauthorized, "Invalid accesstoken!")); } //Create and save to database var newChannel = new Channel { Description = model.Description, ConnectKey = StringOperation.RandomString(20), AppId = token.ApplyAppId }; _dbContext.Channels.Add(newChannel); await _dbContext.SaveChangesAsync(); //return model var viewModel = new CreateChannelViewModel { ChannelId = newChannel.Id, ConnectKey = newChannel.ConnectKey, code = ErrorType.Success, message = "Successfully created your channel!" }; return(Json(viewModel)); }
public async Task <IActionResult> Generate(GenerateAddressModel model) { var app = await _coreApiService.ValidateAccessTokenAsync(model.AccessToken); var appLocal = await _dbContext.Apps.SingleOrDefaultAsync(t => t.AppId == app.AppId); var file = await _dbContext.OSSFile.Include(t => t.BelongingBucket).SingleOrDefaultAsync(t => t.FileKey == model.Id); if (file == null || file.BelongingBucket.BelongingAppId != appLocal.AppId) { return(NotFound()); } // Generate secret var newSecret = new Secret { Value = StringOperation.RandomString(15), FileId = file.FileKey }; _dbContext.Secrets.Add(newSecret); await _dbContext.SaveChangesAsync(); return(Json(new AiurValue <string>(newSecret.Value) { Code = ErrorType.Success, Message = "Successfully created your onetime secret!" })); }
public async Task <IActionResult> ForgotPasswordViaSms(ForgotPasswordViaEmailViewModel model) { var mail = await _dbContext.UserEmails.SingleOrDefaultAsync(t => t.EmailAddress == model.Email.ToLower()); if (mail == null) { return(NotFound()); } var user = await _dbContext .Users .Include(t => t.Emails) .SingleOrDefaultAsync(t => t.Id == mail.OwnerId); if (user.PhoneNumberConfirmed == false) { return(NotFound()); } var code = StringOperation.RandomString(6); user.SMSPasswordResetToken = code; await _userManager.UpdateAsync(user); _cannonService.FireAsync <APISMSSender>(async(sender) => { await sender.SendAsync(user.PhoneNumber, code + " is your Aiursoft password reset code."); }); return(RedirectToAction(nameof(EnterSmsCode), new { model.Email })); }
public async Task <IActionResult> ForgotPasswordViaSMS(ForgotPasswordViaEmailViewModel model) { if (ModelState.IsValid) { var user = await _userManager.FindByEmailAsync(model.Email); if (user == null) { model.ModelStateValid = false; ModelState.AddModelError("", $"We can't find an account with email:`{model.Email}`!"); return(View(model)); } if (user.PhoneNumberConfirmed == false) { model.ModelStateValid = false; ModelState.AddModelError("", "Your account did not bind a valid phone number!"); return(View(model)); } var code = StringOperation.RandomString(6); user.SMSPasswordResetToken = code; await _userManager.UpdateAsync(user); await _smsSender.SendAsync(user.PhoneNumber, code + " is your Aiursoft password reset code."); return(RedirectToAction(nameof(EnterSMSCode), new { model.Email })); } return(View(model)); }
public void AddFriend(string userId1, string userId2) { this.PrivateConversations.Add(new PrivateConversation { RequesterId = userId1, TargetId = userId2, AESKey = StringOperation.RandomString(30) }); }
public App(string seed, string name, string description, Category category, Platform platform) { this.AppId = (seed + DateTime.Now.ToString()).GetMD5(); this.AppSecret = (seed + this.AppId + DateTime.Now.ToString() + StringOperation.RandomString(15)).GetMD5(); this.AppName = name; this.AppDescription = description; this.AppCategory = category; this.AppPlatform = platform; }
public async Task <IActionResult> SendConfirmationEmail(SendConfirmationEmailAddressModel model)//User Id { var accessToken = await _dbContext .AccessToken .SingleOrDefaultAsync(t => t.Value == model.AccessToken); var app = await _developerApiService.AppInfoAsync(accessToken.ApplyAppId); var user = await _userManager.FindByIdAsync(model.Id); var useremail = await _dbContext.UserEmails.SingleOrDefaultAsync(t => t.EmailAddress == model.Email.ToLower()); if (useremail == null) { return(this.Protocal(ErrorType.NotFound, $"Can not find your email:{model.Email}")); } if (useremail.OwnerId != user.Id) { return(this.Protocal(ErrorType.Unauthorized, $"The account you tried to authorize is not an account with id: {model.Id}")); } if (useremail.Validated) { return(this.Protocal(ErrorType.HasDoneAlready, $"The email :{model.Email} was already validated!")); } if (!_dbContext.LocalAppGrant.Exists(t => t.AppID == accessToken.ApplyAppId && t.APIUserId == user.Id)) { return(Json(new AiurProtocal { Code = ErrorType.Unauthorized, Message = "This user did not grant your app!" })); } if (!app.App.ConfirmEmail) { return(this.Protocal(ErrorType.Unauthorized, "You app is not allowed to send confirmation email!")); } //limit the sending frenquency to 3 minutes. if (DateTime.Now > useremail.LastSendTime + new TimeSpan(0, 3, 0)) { var token = StringOperation.RandomString(30); useremail.ValidateToken = token; useremail.LastSendTime = DateTime.Now; await _dbContext.SaveChangesAsync(); var callbackUrl = new AiurUrl(_serviceLocation.API, "User", nameof(EmailConfirm), new { userId = user.Id, code = token }); await _emailSender.SendEmail(useremail.EmailAddress, $"{Values.ProjectName} Account Email Confirmation", $"Please confirm your email by clicking <a href='{callbackUrl}'>here</a>"); } return(this.Protocal(ErrorType.Success, "Successfully sent the validation email.")); }
public async Task TestGetOutter() { var http = _serviceProvider.GetRequiredService <APIProxyService>(); var random = StringOperation.RandomString(100); var result = await http.Get(new AiurUrl("https://postman-echo.com/get", new { a = random })); dynamic resultObject = JObject.Parse(result); Assert.AreEqual(resultObject.args.a.ToString(), random); Assert.IsTrue(resultObject.url.ToString().StartsWith("https://")); }
public App(string seed, string name, string description, Category category, Platform platform, string forceAppId = null, string forceAppSecret = null) { if (!string.IsNullOrWhiteSpace(forceAppId) && !string.IsNullOrWhiteSpace(forceAppSecret)) { this.AppId = forceAppId; this.AppSecret = forceAppSecret; } else { this.AppId = (seed + DateTime.Now.ToString()).GetMD5(); this.AppSecret = (seed + this.AppId + DateTime.Now.ToString() + StringOperation.RandomString(15)).GetMD5(); } this.AppName = name; this.AppDescription = description; this.AppCategory = category; this.AppPlatform = platform; }
public async Task <IActionResult> CreateApp(CreateAppViewModel model) { var _cuser = await GetCurrentUserAsync(); if (!ModelState.IsValid) { model.ModelStateValid = false; model.Recover(_cuser, 1); return(View(model)); } string iconPath = string.Empty; if (Request.Form.Files.Count == 0 || Request.Form.Files.First().Length < 1) { iconPath = Values.DeveloperServerAddress + "/images/appdefaulticon.png"; } else { var iconFile = Request.Form.Files.First(); string DirectoryPath = GetCurrentDirectory() + DirectorySeparatorChar + $@"Storage" + DirectorySeparatorChar; if (Exists(DirectoryPath) == false) { CreateDirectory(DirectoryPath); } var NewFilePath = DirectoryPath + StringOperation.RandomString(10) + GetExtension(iconFile.FileName); var fileStream = new FileStream(NewFilePath, FileMode.Create); await iconFile.CopyToAsync(fileStream); fileStream.Close(); var fileAddress = await ApiService.UploadFile(await AppsContainer.AccessToken()(), Values.AppsIconBucketId, NewFilePath); iconPath = fileAddress.Path; } var _newApp = new App(_cuser.Id, model.AppName, model.AppDescription, model.AppCategory, model.AppPlatform) { CreaterId = _cuser.Id, AppIconAddress = iconPath }; _dbContext.Apps.Add(_newApp); await _dbContext.SaveChangesAsync(); return(RedirectToAction(nameof(ViewApp), new { id = _newApp.AppId })); }
public async Task<IActionResult> ForgotPasswordViaSMS(ForgotPasswordViaEmailViewModel model) { var mail = await _dbContext.UserEmails.SingleOrDefaultAsync(t => t.EmailAddress == model.Email.ToLower()); if (mail == null) { return NotFound(); } var user = await _userManager.FindByIdAsync(mail.OwnerId); if (user.PhoneNumberConfirmed == false) { return NotFound(); } var code = StringOperation.RandomString(6); user.SMSPasswordResetToken = code; await _userManager.UpdateAsync(user); await _smsSender.SendAsync(user.PhoneNumber, code + " is your Aiursoft password reset code."); return RedirectToAction(nameof(EnterSMSCode), new { model.Email }); }
public async Task TestPostInternal() { var http = _serviceProvider.GetRequiredService <HTTPService>(); var random = StringOperation.RandomString(100); var random2 = StringOperation.RandomString(100); var result = await http.Post(new AiurUrl("https://postman-echo.com/post", new { a = random }), new AiurUrl("", new { c = random2 }), true); dynamic resultObject = JObject.Parse(result); Assert.AreEqual(resultObject.args.a.ToString(), random); Assert.AreEqual(resultObject.form.c.ToString(), random2); Assert.IsTrue(resultObject.url.ToString().StartsWith("http://")); }
public async Task <IActionResult> CreateChannel([FromForm] CreateChannelAddressModel model) { //Update app info var app = await ApiService.ValidateAccessTokenAsync(model.AccessToken); var appLocal = await _dbContext.Apps.Include(t => t.Channels).SingleOrDefaultAsync(t => t.Id == app.AppId); if (appLocal == null) { appLocal = new StargateApp { Id = app.AppId, Channels = new List <Channel>() }; _dbContext.Apps.Add(appLocal); } //Create and save to database var newChannel = new Channel { Description = model.Description, ConnectKey = StringOperation.RandomString(20) }; appLocal.Channels.Add(newChannel); await _dbContext.SaveChangesAsync(); //return model var viewModel = new CreateChannelViewModel { ChannelId = newChannel.Id, ConnectKey = newChannel.ConnectKey, code = ErrorType.Success, message = "Successfully created your channel!" }; return(Json(viewModel)); }
public async Task <IActionResult> ChangeIcon(string AppId) { if (Request.Form.Files.Count != 0 && Request.Form.Files.First().Length > 1) { var iconFile = Request.Form.Files.First(); string DirectoryPath = GetCurrentDirectory() + DirectorySeparatorChar + "Storage" + DirectorySeparatorChar; if (Exists(DirectoryPath) == false) { CreateDirectory(DirectoryPath); } var NewFilePath = DirectoryPath + StringOperation.RandomString(10) + GetExtension(iconFile.FileName); var fileStream = new FileStream(NewFilePath, FileMode.Create); await iconFile.CopyToAsync(fileStream); fileStream.Close(); var fileAddress = await ApiService.UploadFile(await AppsContainer.AccessToken()(), Values.AppsIconBucketId, NewFilePath); var appExists = await _dbContext.Apps.FindAsync(AppId); appExists.AppIconAddress = fileAddress.Path; await _dbContext.SaveChangesAsync(); } return(RedirectToAction(nameof(ViewApp), new { id = AppId, JustHaveUpdated = true })); }
public App(string seed, string name) { this.Id = (seed + DateTime.Now.ToString()).GetMD5(); this.Secret = (seed + this.Id + DateTime.Now.ToString() + StringOperation.RandomString(15)).GetMD5(); this.Name = name; }
public async Task SendDebuggingMessages(string AccessToken, int ChannelId) { var random = new Random(); for (int i = 0; i < 1000; i++) { await _messageService.PushMessageAsync(AccessToken, ChannelId, DateTime.Now + StringOperation.RandomString(10)); await Task.Delay(10); } }