public async Task <IdentityResult <ApiKey> > RegisterUserApiKeyAsync(ApiKey apiKey, string userId) { if (apiKey == null) { return(new IdentityResult <ApiKey>("Invalid key details", errorType: ErrorType.InvalidParameters)); } var existKey = await _context.ApiKeys.AnyAsync(item => item.Key.Equals(apiKey.Key)); if (existKey) { return(new IdentityResult <ApiKey>("Key already used", errorType: ErrorType.InvalidParameters)); } var existingUser = await _userManager.FindByNameAsync(userId); // FindByEmailAsync(email); if (existingUser == null) { return(new IdentityResult <ApiKey>("User with this username does not exist", errorType: ErrorType.NotFound)); } apiKey.UserId = existingUser.Id; apiKey.CreationDate = DateTime.Now; var res = await _context.ApiKeys.AddAsync(apiKey); await _context.SaveChangesAsync(); return(new IdentityResult <ApiKey> { Success = true, Object = res.Entity }); }
public async Task <IActionResult> Create([Bind("ContainerName", "ImageID", "VolumeID")] ContainerViewModel containerViewModel) { if (ModelState.IsValid) { ApplicationUser user = await _userManager.GetUserAsync(this.User); var newContainer = await containerViewModel.ValidateContainerAsync(_context, user); await _context.Mounting.AddRangeAsync(newContainer.Mountings); await _context.Container.AddAsync(newContainer); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["Images"] = new SelectList(_context.Image, "VolumeID", "Tag"); ViewData["Volumes"] = new SelectList(_context.Volume.Where(v => v.Path == VolumePath.Home), "VolumeID", "Name"); return(View(containerViewModel)); }
public async Task <IActionResult> Create(Product product, int?id) { if (ModelState.IsValid) { var user = await _userManager.GetUserAsync(HttpContext.User); var store = _context.Stores.Where(i => i.UserId == user.Id).FirstOrDefault(); product.StoreModelId = store.Id; product.Store = store; _context.Add(product); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } else { } return(View(product)); }
public async Task <IActionResult> TryDiscardChange([Bind("BaseImageTag,VolumeID,UserID,Tag,CreateTime,LastModifiedTime")] Image image) { try { var user = await _userManager.GetUserAsync(this.User); image = await validateImage(user, image); return(Ok()); } catch (ArgumentException) { image = await _context.Image.FirstOrDefaultAsync(f => f.Tag == image.Tag); _context.Remove(image); await _context.SaveChangesAsync(); return(Ok()); } }
public async Task <bool> Save() { return(await _db.SaveChangesAsync() > 0); }
public async Task SeedAsync() { var identityResources = new IdentityResource[] { new IdentityResources.OpenId(), //new IdentityResources.Profile(), //new IdentityResources.Email(), //new IdentityResources.Phone(), //new IdentityResources.Address() }; var apiResources = new[] { new ApiResource { Name = "api", DisplayName = "API", Description = "API", ApiSecrets = { new Secret("7c47d19600af41c697fb697dd7d00fa5", "App Master Secret"), new Secret { Type = IdentityServerConstants.SecretTypes.X509CertificateBase64, Value = "MIIDATCCAe2gAwIBAgIQoHUYAquk9rBJcq8W+F0FAzAJBgUrDgMCHQUAMBIxEDAOBgNVBAMTB0RldlJvb3QwHhcNMTAwMTIwMjMwMDAwWhcNMjAwMTIwMjMwMDAwWjARMQ8wDQYDVQQDEwZDbGllbnQwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDSaY4x1eXqjHF1iXQcF3pbFrIbmNw19w/IdOQxbavmuPbhY7jX0IORu/GQiHjmhqWt8F4G7KGLhXLC1j7rXdDmxXRyVJBZBTEaSYukuX7zGeUXscdpgODLQVay/0hUGz54aDZPAhtBHaYbog+yH10sCXgV1Mxtzx3dGelA6pPwiAmXwFxjJ1HGsS/hdbt+vgXhdlzud3ZSfyI/TJAnFeKxsmbJUyqMfoBl1zFKG4MOvgHhBjekp+r8gYNGknMYu9JDFr1ue0wylaw9UwG8ZXAkYmYbn2wN/CpJl3gJgX42/9g87uLvtVAmz5L+rZQTlS1ibv54ScR2lcRpGQiQav/LAgMBAAGjXDBaMBMGA1UdJQQMMAoGCCsGAQUFBwMCMEMGA1UdAQQ8MDqAENIWANpX5DZ3bX3WvoDfy0GhFDASMRAwDgYDVQQDEwdEZXZSb290ghAsWTt7E82DjU1E1p427Qj2MAkGBSsOAwIdBQADggEBADLje0qbqGVPaZHINLn+WSM2czZk0b5NG80btp7arjgDYoWBIe2TSOkkApTRhLPfmZTsaiI3Ro/64q+Dk3z3Kt7w+grHqu5nYhsn7xQFAQUf3y2KcJnRdIEk0jrLM4vgIzYdXsoC6YO+9QnlkNqcN36Y8IpSVSTda6gRKvGXiAhu42e2Qey/WNMFOL+YzMXGt/nDHL/qRKsuXBOarIb++43DV3YnxGTx22llhOnPpuZ9/gnNY7KLjODaiEciKhaKqt/b57mTEz4jTF4kIg6BP03MUfDXeVlM1Qf1jB43G2QQ19n5lUiqTpmQkcfLfyci2uBZ8BkOhXr3Vk9HIk/xBXQ=" } }, UserClaims = { JwtClaimTypes.Name, JwtClaimTypes.GivenName, JwtClaimTypes.FamilyName, JwtClaimTypes.Email, JwtClaimTypes.EmailVerified }, Scopes = { new Scope { Name = "api.full_access", DisplayName = "Full Access", Description = "Full Access to API" }, new Scope { Name = "api.read_only", DisplayName = "Read-Only Access", Description = "Read-Only Access to API" } } } }; var clients = new[] { new Client { ClientId = "client.reference", ClientName = "Resource Owner Password (Reference)", ClientSecrets = { new Secret("a3c1210604414881b85064b172b28265", "Client Master Secret") }, AllowedGrantTypes = GrantTypes.ResourceOwnerPassword, AllowedScopes = { IdentityServerConstants.StandardScopes.OpenId, "api.full_access" }, AccessTokenType = AccessTokenType.Reference }, new Client { ClientId = "client.rop", ClientName = "Resource Owner Password", ClientSecrets = { new Secret("a3c1210604414881b85064b172b28265", "Client Master Secret") }, AllowedGrantTypes = GrantTypes.ResourceOwnerPassword, AllowedScopes = { IdentityServerConstants.StandardScopes.OpenId, "api.full_access" }, AllowOfflineAccess = true }, new Client { ClientId = "client.rop.public", ClientName = "Resource Owner Password (Public)", RequireClientSecret = false, AllowedGrantTypes = GrantTypes.ResourceOwnerPassword, AllowedScopes = { IdentityServerConstants.StandardScopes.OpenId, "api.full_access" } }, new Client { ClientId = "client.cc", ClientName = "Client Credentials", ClientSecrets = { new Secret("a3c1210604414881b85064b172b28265", "Client Master Secret") }, AllowedGrantTypes = GrantTypes.ClientCredentials, AllowedScopes = { IdentityServerConstants.StandardScopes.OpenId, "api.full_access" } }, new Client { ClientId = "client.cc.public", ClientName = "Client Credentials (Public)", RequireClientSecret = false, AllowedGrantTypes = GrantTypes.ClientCredentials, AllowedScopes = { IdentityServerConstants.StandardScopes.OpenId, "api.full_access" } }, new Client { ClientId = "client.implicit", ClientName = "Implicit", ClientUri = "https://www.smartiks.com.tr", LogoUri = "https://media.licdn.com/dms/image/C4E0BAQES3PtJPELJwg/company-logo_200_200/0?e=2159024400&v=beta&t=x0iiTxBt7yV9xPb0LKqzJKaT-_snRUUqDpX_-Wq83sU", RequireClientSecret = false, AllowAccessTokensViaBrowser = true, AllowedGrantTypes = GrantTypes.Implicit, AllowedScopes = { IdentityServerConstants.StandardScopes.OpenId, "api.full_access" }, AllowedCorsOrigins = { "http://*****:*****@yopmail.com", EmailConfirmed = false, SecurityStamp = Guid.NewGuid().ToString("D") }; var result = await userManager.CreateAsync(user, "@ZHmc57"); if (!result.Succeeded) { throw new Exception(string.Join(Environment.NewLine, result.Errors.Select(e => $"{e.Code} {e.Description}").ToArray())); } result = await userManager.AddClaimsAsync(user, new[] { new Claim(JwtClaimTypes.Name, "Murat Atay"), new Claim(JwtClaimTypes.GivenName, "Murat"), new Claim(JwtClaimTypes.FamilyName, "Atay"), new Claim(JwtClaimTypes.Email, user.Email), new Claim(JwtClaimTypes.EmailVerified, user.EmailConfirmed.ToString(), ClaimValueTypes.Boolean) }); if (!result.Succeeded) { throw new Exception(string.Join(Environment.NewLine, result.Errors.Select(e => $"{e.Code} {e.Description}").ToArray())); } }
public async Task <IActionResult> AddStore(StoreModel model, IEnumerable <IFormFile> files, IFormFile fileProfile) { var user = await _userManager.GetUserAsync(HttpContext.User); var storex = _context.Stores.Where(i => i.UserId == user.Id); if (storex.Count() > 0) { ModelState.AddModelError("", "Zaten bir dükkanınız bulunmakta."); } else { if (ModelState.IsValid) { var list = new List <Image>(); string fileName = ""; string fileNamee = ""; int i = 0; if (files.Count() > 10) { ModelState.AddModelError("", "10 adet fotoğraf yüklemelisiniz."); } else if (files.Count() <= 0) { ModelState.AddModelError("", "Fotoğraf yüklemelisiniz."); } else { if (fileProfile == null || fileProfile.Length <= 0) { ModelState.AddModelError("", "Profil fotoğrafı seçmelisiniz."); } else { var extensition = Path.GetExtension(fileProfile.FileName); if (extensition == ".jpg" || extensition == ".png") { var dir = _env.ContentRootPath + "\\upload"; var randomFilename = Path.GetRandomFileName(); fileNamee = Path.ChangeExtension(randomFilename, ".jpg"); var path = Path.Combine(dir, fileNamee); using (var fileStream = new FileStream(path, FileMode.Create, FileAccess.Write)) { fileProfile.CopyTo(fileStream); foreach (var file in files) { var dirr = _env.ContentRootPath + "\\upload"; var randomFilenamee = Path.GetRandomFileName(); fileName = Path.ChangeExtension(randomFilenamee, ".jpg"); var pathh = Path.Combine(dir, fileName); using (var filestream = new FileStream(pathh, FileMode.Create, FileAccess.Write)) { list.Add(new Image() { Name = fileName }); file.CopyTo(filestream); } } var store = new StoreModel() { Address = model.Address, Description = model.Description, Name = model.Name, PhoneNumber = model.PhoneNumber, Rate = 0, Type = model.Type, UserId = user.Id, City = model.City, District = model.District, Images = list, ProfilePhoto = fileNamee }; await _context.Stores.AddAsync(store); await _context.SaveChangesAsync(); return(RedirectToAction("Index")); } } } } } else { return(View(model)); } } return(View(model)); }
public async Task <bool> SaveChangesAsync() => await _Context.SaveChangesAsync() > 0;