diff --git a/BaseDomain/Base/AEntity.cs b/BaseDomain/Base/AEntity.cs new file mode 100644 index 0000000..9449d08 --- /dev/null +++ b/BaseDomain/Base/AEntity.cs @@ -0,0 +1,78 @@ +using BaseDomain.SimpleValidator; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BaseDomain.Base +{ + public abstract class AEntity where TKey : class + where T : class + { + ObjectValidatorBuilder objectValidatorBuilder; + bool rulesAdded; + + public ObjectValidatorBuilder ValidatorBuilder { get { return objectValidatorBuilder; } } + + public AEntity() + { + T entity; + try + { + entity = (T)Convert.ChangeType(this, typeof(T)); + } + catch (InvalidCastException) + { + entity = default; + } + + objectValidatorBuilder = new ObjectValidatorBuilder(entity); + AddRules(); + } + + public ObjectValidatorBuilder InitValidator() + { + T entity; + try + { + entity = (T)Convert.ChangeType(this, typeof(T)); + } + catch (InvalidCastException) + { + entity = default; + } + + objectValidatorBuilder = new ObjectValidatorBuilder(entity); + return objectValidatorBuilder; + } + + public abstract TKey Id { get; set; } + + public void ValidateAndThrow() + { + SetClearAndRules(); + objectValidatorBuilder.ThrowErrorMessages(); + } + + public string GetErrorMessages() + { + SetClearAndRules(); + return objectValidatorBuilder.ErrorMessagesAsString(); + } + + public bool IsValid() + { + SetClearAndRules(); + return objectValidatorBuilder.IsValid(); + } + + private void SetClearAndRules() + { + objectValidatorBuilder.ClearRules(); + AddRules(); + objectValidatorBuilder.Build(); + } + public abstract void AddRules(); + } +} diff --git a/BaseDomain/Base/AValueObject.cs b/BaseDomain/Base/AValueObject.cs new file mode 100644 index 0000000..e0c2191 --- /dev/null +++ b/BaseDomain/Base/AValueObject.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BaseDomain +{ + public abstract class AValueObject + { + protected static bool EqualOperator(AValueObject left, AValueObject right) + { + if (ReferenceEquals(left, null) ^ ReferenceEquals(right, null)) + { + return false; + } + return ReferenceEquals(left, right) || left.Equals(right); + } + + protected static bool NotEqualOperator(AValueObject left, AValueObject right) + { + return !EqualOperator(left, right); + } + protected abstract IEnumerable GetEqualityComponents(); + + public override bool Equals(object obj) + { + if (obj == null || obj.GetType() != GetType()) + { + return false; + } + + var other = (AValueObject)obj; + + return GetEqualityComponents().SequenceEqual(other.GetEqualityComponents()); + } + + public static bool operator ==(AValueObject one, AValueObject two) + { + return EqualOperator(one, two); + } + + public static bool operator !=(AValueObject one, AValueObject two) + { + return NotEqualOperator(one, two); + } + + public override int GetHashCode() + { + return GetEqualityComponents() + .Select(x => x != null ? x.GetHashCode() : 0) + .Aggregate((x, y) => x ^ y); + } + + public Func GetValidationFunc() => GetValidationExpression; + public abstract bool GetValidationExpression(); + + public const string ErrorMessage = ""; + + public bool IsValid { get; protected set; } + } +} diff --git a/BaseDomain/BaseDomain.csproj b/BaseDomain/BaseDomain.csproj new file mode 100644 index 0000000..d53549b --- /dev/null +++ b/BaseDomain/BaseDomain.csproj @@ -0,0 +1,21 @@ + + + + net7.0 + enable + enable + + + + + + + + + + + + + + + diff --git a/BaseDomain/Repositories/Contracts/IRepoCommand.cs b/BaseDomain/Repositories/Contracts/IRepoCommand.cs new file mode 100644 index 0000000..16535d3 --- /dev/null +++ b/BaseDomain/Repositories/Contracts/IRepoCommand.cs @@ -0,0 +1,10 @@ +namespace DIC.Test.Data.Contracts +{ + public interface IRepoCommand where T : class + where TId : struct + { + void Add(T entity); + void Update(T entity); + void Delete(T entity); + } +} diff --git a/BaseDomain/Repositories/Contracts/IRepoQuery.cs b/BaseDomain/Repositories/Contracts/IRepoQuery.cs new file mode 100644 index 0000000..ab8f03c --- /dev/null +++ b/BaseDomain/Repositories/Contracts/IRepoQuery.cs @@ -0,0 +1,14 @@ +using System.Linq.Expressions; + +namespace DIC.Test.Data.Contracts +{ + public interface IRepoQuery where T : class + where TId : struct + { + public T GetById(TId id); + + public IEnumerable GetAll(); + + public IEnumerable FindAll(Expression expression); + } +} diff --git a/BaseDomain/Repositories/Contracts/IRepoReadOnly.cs b/BaseDomain/Repositories/Contracts/IRepoReadOnly.cs new file mode 100644 index 0000000..b5292f0 --- /dev/null +++ b/BaseDomain/Repositories/Contracts/IRepoReadOnly.cs @@ -0,0 +1,8 @@ +namespace DIC.Test.Data.Contracts +{ + public interface IRepoReadOnly : IRepoQuery + where T : class + where TId : struct + { + } +} diff --git a/BaseDomain/Repositories/Contracts/IRepository.cs b/BaseDomain/Repositories/Contracts/IRepository.cs new file mode 100644 index 0000000..11ac11f --- /dev/null +++ b/BaseDomain/Repositories/Contracts/IRepository.cs @@ -0,0 +1,10 @@ +using System.Runtime.InteropServices; + +namespace DIC.Test.Data.Contracts +{ + public interface IRepository : IRepoCommand, IRepoQuery + where T : class + where TId : struct + { + } +} diff --git a/BaseDomain/Results/Error.cs b/BaseDomain/Results/Error.cs new file mode 100644 index 0000000..6466204 --- /dev/null +++ b/BaseDomain/Results/Error.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BaseDomain.Results +{ + public class Error + { + public enum ErrorTypeEnum + { + None = 0, //Erro vazio (para result) + Failure = 1, //Quando for uma falha que eu queira retornar no lugar de uma Exception + Validation = 2, //Quando for um problema de validação + Others = 3 //Inesperado ou sem categoria + } + + public Error(ErrorTypeEnum error, string message, string description="") + { + ErrorType = error; + Message = message; + } + + public static Error None => new Error(ErrorTypeEnum.None, string.Empty, string.Empty); + + public ErrorTypeEnum ErrorType { get; } + public string Message { get; } + public string Description { get; } + + public static implicit operator string(Error error) => error.Message; + + //Permitir atribuir um error diretamente ao resultado. + public static implicit operator Result(Error error) => Result.Failure(error); + } +} diff --git a/BaseDomain/Results/Result.cs b/BaseDomain/Results/Result.cs new file mode 100644 index 0000000..f6b11c5 --- /dev/null +++ b/BaseDomain/Results/Result.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BaseDomain.Results +{ + public class Result + { + protected Result(bool isSuccess, Error error) + { + if (isSuccess && error != Error.None) + { + throw new InvalidOperationException(); + } + if (!isSuccess && error == Error.None) + { + throw new InvalidOperationException(); + } + + this.IsSuccess = isSuccess; + this.Error = error; + } + + public bool IsSuccess { get; } + public bool IsFalilure => !IsSuccess; + public Error Error { get; } + + public static Result Success() => new(true, Error.None); + public static Result Failure(Error error) => new(false, Error.None); + } +} diff --git a/BaseDomain/Results/ResultT.cs b/BaseDomain/Results/ResultT.cs new file mode 100644 index 0000000..0eaf098 --- /dev/null +++ b/BaseDomain/Results/ResultT.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BaseDomain.Results +{ + public class Result : Result + { + private readonly TValue _value; + + protected Result(TValue value, bool isSuccess, Error error) : base(isSuccess, error) + { + _value = value; + } + + protected Result(TValue value) : base(true, Error.None) + { + _value = value; + } + + public TValue Value => IsSuccess ? _value : throw new InvalidOperationException("O valor náo pode ser processado!"); + + public static implicit operator Result(TValue? value) => Create(value); + public static Result Success(TValue value) => new(value); + + public static Result Create(TValue value) + { + return new Result(value, true, Error.None); + } + + } +} diff --git a/BaseDomain/SimpleValidator/ObjectValidatorBuilder.cs b/BaseDomain/SimpleValidator/ObjectValidatorBuilder.cs new file mode 100644 index 0000000..f23ddc0 --- /dev/null +++ b/BaseDomain/SimpleValidator/ObjectValidatorBuilder.cs @@ -0,0 +1,102 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BaseDomain.SimpleValidator +{ + public class ObjectValidatorBuilder + { + /// + /// model that is validated + /// + private T model; + private bool isValid; + + public ObjectValidatorBuilder(T objectOrEntity) + { + model = objectOrEntity; + } + + /// + /// Check if model meetf all rules + /// + public ObjectValidatorBuilder Build() + { + //select all ruiles without OnlyIf expression or with satisfied OnlyIf expression + var invalidResults = _rules.Where(m => m.OnlyIf == null || (m.OnlyIf != null && m.OnlyIf(model))); + + //select all rules that arent satisfied + invalidResults = invalidResults.Where(m => !m.ValidationExpression(model)); + + //set error messages of unsatisfied rules + ErrorMessages = invalidResults.Select(m => m.ErrorMessage).ToList(); + + isValid =!invalidResults.Any(); + + return this; + } + + public bool IsValid() + { + return isValid; + } + + public void ThrowErrorMessages() + { + if (!isValid) throw new ArgumentException(this.ErrorMessagesAsString()); + } + + public string ErrorMessagesAsString() + { + return String.Join("\n", this.ErrorMessages); + } + + /// + /// Get error messages for rules that are not satisfied + /// + public List ErrorMessages { get; set; } + + /// + /// List of rules that are specified for model + /// + private readonly List> _rules = new List>(); + + public ObjectValidatorBuilder AddRule(Func validationExpression, Func onlyIf, String errorMessage) + { + _rules.Add(new ValidationRule() + { + ValidationExpression = validationExpression, + OnlyIf = onlyIf, + ErrorMessage = errorMessage + }); + + return this; + } + + public ObjectValidatorBuilder AddRule(Func validationExpression, String errorMessage) + { + AddRule(validationExpression, null, errorMessage); + return this; + } + + public ObjectValidatorBuilder AddRule(AValueObject valueObject) + { + + AddRule((valueObject) => (valueObject as AValueObject).GetValidationExpression(), null, AValueObject.ErrorMessage); + return this; + } + + public ObjectValidatorBuilder AddRule(ValidationRule rule) + { + AddRule(rule); + return this; + } + + public void ClearRules() + { + _rules.Clear(); + } + } +} diff --git a/BaseDomain/SimpleValidator/ValidationRule.cs b/BaseDomain/SimpleValidator/ValidationRule.cs new file mode 100644 index 0000000..50c620c --- /dev/null +++ b/BaseDomain/SimpleValidator/ValidationRule.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BaseDomain.SimpleValidator +{ + public class ValidationRule + { + public ValidationRule() + { + } + + public ValidationRule(Func validationExpression, Func onlyIf, String errorMessage) + { + ValidationExpression = validationExpression; + OnlyIf = onlyIf; + ErrorMessage = errorMessage; + } + public ValidationRule(Func validationExpression, String errorMessage) + { + ValidationExpression = validationExpression; + ErrorMessage = errorMessage; + } + /// + /// Validation rule expression, examp. check is string null or empty !string.IsNullOrEmpty(o.Name) + /// + public Func ValidationExpression { get; set; } + + /// + /// You can specify OnlyIf expression, if this expresion is specified than ValidationExpression is going to be evaluated only if OnlyIf rule is satisfied + /// + public Func OnlyIf { get; set; } + + /// + /// Specify error message that will be returned if rule is not satisifed + /// + public string ErrorMessage { get; set; } + } +} diff --git a/MVCPostall.sln b/MVCPostall.sln new file mode 100644 index 0000000..891e3e2 --- /dev/null +++ b/MVCPostall.sln @@ -0,0 +1,43 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.7.34031.279 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Postall", "Postall\Postall.csproj", "{2913C42A-071B-483D-8004-1D9B4E10557E}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Postall.Infra", "Postall.Infra\Postall.Infra.csproj", "{6CEE683B-CEC7-42EC-AB67-CFA124DDB8FD}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Postall.Domain", "Postall.Domain\Postall.Domain.csproj", "{373B1329-C49C-4F24-B67F-2F977225160A}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BaseDomain", "BaseDomain\BaseDomain.csproj", "{72324CE0-8009-4876-9CF9-9F2BA8288B87}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {2913C42A-071B-483D-8004-1D9B4E10557E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2913C42A-071B-483D-8004-1D9B4E10557E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2913C42A-071B-483D-8004-1D9B4E10557E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2913C42A-071B-483D-8004-1D9B4E10557E}.Release|Any CPU.Build.0 = Release|Any CPU + {6CEE683B-CEC7-42EC-AB67-CFA124DDB8FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6CEE683B-CEC7-42EC-AB67-CFA124DDB8FD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6CEE683B-CEC7-42EC-AB67-CFA124DDB8FD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6CEE683B-CEC7-42EC-AB67-CFA124DDB8FD}.Release|Any CPU.Build.0 = Release|Any CPU + {373B1329-C49C-4F24-B67F-2F977225160A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {373B1329-C49C-4F24-B67F-2F977225160A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {373B1329-C49C-4F24-B67F-2F977225160A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {373B1329-C49C-4F24-B67F-2F977225160A}.Release|Any CPU.Build.0 = Release|Any CPU + {72324CE0-8009-4876-9CF9-9F2BA8288B87}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {72324CE0-8009-4876-9CF9-9F2BA8288B87}.Debug|Any CPU.Build.0 = Debug|Any CPU + {72324CE0-8009-4876-9CF9-9F2BA8288B87}.Release|Any CPU.ActiveCfg = Release|Any CPU + {72324CE0-8009-4876-9CF9-9F2BA8288B87}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EC4AB36F-49CB-4819-ACA4-3A14CB1D9B50} + EndGlobalSection +EndGlobal diff --git a/VCart.Domain/Entities/BusinessAreas.cs b/Postall.Domain/Entities/BusinessAreas.cs similarity index 100% rename from VCart.Domain/Entities/BusinessAreas.cs rename to Postall.Domain/Entities/BusinessAreas.cs diff --git a/VCart.Domain/Entities/BusinessAres.cs b/Postall.Domain/Entities/BusinessAres.cs similarity index 100% rename from VCart.Domain/Entities/BusinessAres.cs rename to Postall.Domain/Entities/BusinessAres.cs diff --git a/VCart.Domain/Entities/LinkBio.cs b/Postall.Domain/Entities/LinkBio.cs similarity index 100% rename from VCart.Domain/Entities/LinkBio.cs rename to Postall.Domain/Entities/LinkBio.cs diff --git a/VCart.Domain/Entities/PageBio.cs b/Postall.Domain/Entities/PageBio.cs similarity index 100% rename from VCart.Domain/Entities/PageBio.cs rename to Postall.Domain/Entities/PageBio.cs diff --git a/VCart.Domain/Entities/PersonUser.cs b/Postall.Domain/Entities/PersonUser.cs similarity index 100% rename from VCart.Domain/Entities/PersonUser.cs rename to Postall.Domain/Entities/PersonUser.cs diff --git a/VCart.Domain/Entities/ServiceLinkPart.cs b/Postall.Domain/Entities/ServiceLinkPart.cs similarity index 100% rename from VCart.Domain/Entities/ServiceLinkPart.cs rename to Postall.Domain/Entities/ServiceLinkPart.cs diff --git a/VCart.Domain/Entities/ServiceLinks.cs b/Postall.Domain/Entities/ServiceLinks.cs similarity index 100% rename from VCart.Domain/Entities/ServiceLinks.cs rename to Postall.Domain/Entities/ServiceLinks.cs diff --git a/VCart.Domain/Entities/UserPlan.cs b/Postall.Domain/Entities/UserPlan.cs similarity index 100% rename from VCart.Domain/Entities/UserPlan.cs rename to Postall.Domain/Entities/UserPlan.cs diff --git a/VCart.Domain/Blinks.Domain.csproj b/Postall.Domain/Postall.Domain.csproj similarity index 100% rename from VCart.Domain/Blinks.Domain.csproj rename to Postall.Domain/Postall.Domain.csproj diff --git a/VCart.Domain/ValueObjects/DateBirth.cs b/Postall.Domain/ValueObjects/DateBirth.cs similarity index 100% rename from VCart.Domain/ValueObjects/DateBirth.cs rename to Postall.Domain/ValueObjects/DateBirth.cs diff --git a/VCart.Domain/ValueObjects/DateChanged.cs b/Postall.Domain/ValueObjects/DateChanged.cs similarity index 100% rename from VCart.Domain/ValueObjects/DateChanged.cs rename to Postall.Domain/ValueObjects/DateChanged.cs diff --git a/VCart.Domain/ValueObjects/Email.cs b/Postall.Domain/ValueObjects/Email.cs similarity index 100% rename from VCart.Domain/ValueObjects/Email.cs rename to Postall.Domain/ValueObjects/Email.cs diff --git a/VCart.Domain/ValueObjects/Id.cs b/Postall.Domain/ValueObjects/Id.cs similarity index 100% rename from VCart.Domain/ValueObjects/Id.cs rename to Postall.Domain/ValueObjects/Id.cs diff --git a/VCart.Domain/ValueObjects/Name.cs b/Postall.Domain/ValueObjects/Name.cs similarity index 100% rename from VCart.Domain/ValueObjects/Name.cs rename to Postall.Domain/ValueObjects/Name.cs diff --git a/VCart.Domain/ValueObjects/Phone.cs b/Postall.Domain/ValueObjects/Phone.cs similarity index 100% rename from VCart.Domain/ValueObjects/Phone.cs rename to Postall.Domain/ValueObjects/Phone.cs diff --git a/VCart.Domain/ValueObjects/Username.cs b/Postall.Domain/ValueObjects/Username.cs similarity index 100% rename from VCart.Domain/ValueObjects/Username.cs rename to Postall.Domain/ValueObjects/Username.cs diff --git a/VCart.Infra/MongoDB/MongoDBContext.cs b/Postall.Infra/MongoDB/MongoDBContext.cs similarity index 100% rename from VCart.Infra/MongoDB/MongoDBContext.cs rename to Postall.Infra/MongoDB/MongoDBContext.cs diff --git a/VCart.Infra/MongoDB/UserPerson.cs b/Postall.Infra/MongoDB/UserPerson.cs similarity index 100% rename from VCart.Infra/MongoDB/UserPerson.cs rename to Postall.Infra/MongoDB/UserPerson.cs diff --git a/VCart.Infra/Blinks.Infra.csproj b/Postall.Infra/Postall.Infra.csproj similarity index 100% rename from VCart.Infra/Blinks.Infra.csproj rename to Postall.Infra/Postall.Infra.csproj diff --git a/VCart/.dockerignore b/Postall/.dockerignore similarity index 100% rename from VCart/.dockerignore rename to Postall/.dockerignore diff --git a/VCart/Controllers/CartHomeController.cs b/Postall/Controllers/CartHomeController.cs similarity index 86% rename from VCart/Controllers/CartHomeController.cs rename to Postall/Controllers/CartHomeController.cs index 5e1ed80..210d240 100644 --- a/VCart/Controllers/CartHomeController.cs +++ b/Postall/Controllers/CartHomeController.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Mvc; -namespace Blinks.Controllers +namespace Postall.Controllers { public class CartHomeController : Controller { diff --git a/VCart/Controllers/HomeController.cs b/Postall/Controllers/HomeController.cs similarity index 96% rename from VCart/Controllers/HomeController.cs rename to Postall/Controllers/HomeController.cs index d9491cc..c38052e 100644 --- a/VCart/Controllers/HomeController.cs +++ b/Postall/Controllers/HomeController.cs @@ -2,7 +2,7 @@ using System.Diagnostics; using Blinks.Models; -namespace Blinks.Controllers +namespace Postall.Controllers { public class HomeController : Controller { diff --git a/VCart/Controllers/LanguageController.cs b/Postall/Controllers/LanguageController.cs similarity index 95% rename from VCart/Controllers/LanguageController.cs rename to Postall/Controllers/LanguageController.cs index 333e780..a995750 100644 --- a/VCart/Controllers/LanguageController.cs +++ b/Postall/Controllers/LanguageController.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Mvc; using System.Globalization; -namespace Blinks.Controllers +namespace Postall.Controllers { public class LanguageController : Controller { diff --git a/VCart/Controllers/LoginController.cs b/Postall/Controllers/LoginController.cs similarity index 89% rename from VCart/Controllers/LoginController.cs rename to Postall/Controllers/LoginController.cs index 10688a0..594336f 100644 --- a/VCart/Controllers/LoginController.cs +++ b/Postall/Controllers/LoginController.cs @@ -6,7 +6,7 @@ using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication; using Stripe; -namespace Blinks.Controllers +namespace Postall.Controllers { public class LoginController : Controller { @@ -38,9 +38,10 @@ namespace Blinks.Controllers [ValidateAntiForgeryToken] public ActionResult ExternalLoginGoogle(string provider, string returnUrl) { - var redirectUrl = Url.Action("ExternalLoginCallback", "Login", new { ReturnUrl = returnUrl }); - var properties = new AuthenticationProperties { RedirectUri = "http://localhost:5094" + redirectUrl }; - return Challenge(properties, "Google"); + var redirectUrl = $"{HttpContext.Request.Scheme}://{HttpContext.Request.Host}{Url.Action("ExternalLoginCallback", "Login")}"; + //var properties = new AuthenticationProperties { RedirectUri = "https://localhost:7078" + redirectUrl }; + var properties = new AuthenticationProperties { RedirectUri = redirectUrl }; + return Challenge(properties, "Google"); } [AllowAnonymous] diff --git a/Postall/Controllers/OtherLoginsController.cs b/Postall/Controllers/OtherLoginsController.cs new file mode 100644 index 0000000..6c1e76f --- /dev/null +++ b/Postall/Controllers/OtherLoginsController.cs @@ -0,0 +1,52 @@ +// AccountController.cs +using Microsoft.AspNetCore.Authentication; +using Microsoft.AspNetCore.Authentication.Facebook; +using Microsoft.AspNetCore.Mvc; + +namespace Postall.Controllers +{ + public class OtherLoginsController : Controller + { + [HttpGet] + public IActionResult Index() + { + return View(); + } + + [HttpGet] + public IActionResult FacebookLogin() + { + var properties = new AuthenticationProperties { RedirectUri = Url.Action("FacebookResponse") }; + return Challenge(properties, FacebookDefaults.AuthenticationScheme); + } + + [HttpGet] + public async Task FacebookResponse() + { + var result = await HttpContext.AuthenticateAsync(FacebookDefaults.AuthenticationScheme); + + if (!result.Succeeded) + return RedirectToAction("Login"); + + var claims = result.Principal.Identities.FirstOrDefault() + .Claims.Select(claim => new + { + claim.Issuer, + claim.OriginalIssuer, + claim.Type, + claim.Value + }); + + // Aqui você pode implementar sua lógica de login + // Por exemplo, criar ou atualizar o usuário no banco de dados + + return RedirectToAction("Index", "Home"); + } + + [HttpPost] + public IActionResult Logout() + { + return SignOut("Cookies", FacebookDefaults.AuthenticationScheme); + } + } +} \ No newline at end of file diff --git a/VCart/Controllers/PayController.cs b/Postall/Controllers/PayController.cs similarity index 98% rename from VCart/Controllers/PayController.cs rename to Postall/Controllers/PayController.cs index c0227fb..bfdf9a7 100644 --- a/VCart/Controllers/PayController.cs +++ b/Postall/Controllers/PayController.cs @@ -2,7 +2,7 @@ using Stripe; using Stripe.Checkout; -namespace Blinks.Controllers +namespace Postall.Controllers { [Route("Pay")] public class PayController : Controller diff --git a/VCart/Controllers/PlansController.cs b/Postall/Controllers/PlansController.cs similarity index 97% rename from VCart/Controllers/PlansController.cs rename to Postall/Controllers/PlansController.cs index 2ac88cb..18e9dcd 100644 --- a/VCart/Controllers/PlansController.cs +++ b/Postall/Controllers/PlansController.cs @@ -4,7 +4,7 @@ using Stripe; using Stripe.Checkout; using Blinks.Models; -namespace Blinks.Controllers +namespace Postall.Controllers { public class PlansController : Controller { diff --git a/VCart/Controllers/SignInController.cs b/Postall/Controllers/SignInController.cs similarity index 93% rename from VCart/Controllers/SignInController.cs rename to Postall/Controllers/SignInController.cs index c1e2c98..0a2d47a 100644 --- a/VCart/Controllers/SignInController.cs +++ b/Postall/Controllers/SignInController.cs @@ -1,7 +1,7 @@ using Microsoft.AspNetCore.Mvc; using System.Diagnostics; -namespace Blinks.Controllers +namespace Postall.Controllers { [Route("signin-microsoft")] public class SignInController : Controller diff --git a/VCart/Controllers/StartupController.cs b/Postall/Controllers/StartupController.cs similarity index 85% rename from VCart/Controllers/StartupController.cs rename to Postall/Controllers/StartupController.cs index 85ba2ff..defbd09 100644 --- a/VCart/Controllers/StartupController.cs +++ b/Postall/Controllers/StartupController.cs @@ -1,6 +1,6 @@ using Microsoft.AspNetCore.Mvc; -namespace Blinks.Controllers +namespace Postall.Controllers { public class StartupController : Controller { diff --git a/VCart/Dockerfile b/Postall/Dockerfile similarity index 100% rename from VCart/Dockerfile rename to Postall/Dockerfile diff --git a/VCart/LogConfig/LogCredentials.cs b/Postall/LogConfig/LogCredentials.cs similarity index 100% rename from VCart/LogConfig/LogCredentials.cs rename to Postall/LogConfig/LogCredentials.cs diff --git a/VCart/LogConfig/LogLabelProvider.cs b/Postall/LogConfig/LogLabelProvider.cs similarity index 100% rename from VCart/LogConfig/LogLabelProvider.cs rename to Postall/LogConfig/LogLabelProvider.cs diff --git a/VCart/Middle/RequestLocalizationMiddleware.cs b/Postall/Middle/RequestLocalizationMiddleware.cs similarity index 100% rename from VCart/Middle/RequestLocalizationMiddleware.cs rename to Postall/Middle/RequestLocalizationMiddleware.cs diff --git a/VCart/Models/ChangeViewModel.cs b/Postall/Models/ChangeViewModel.cs similarity index 100% rename from VCart/Models/ChangeViewModel.cs rename to Postall/Models/ChangeViewModel.cs diff --git a/VCart/Models/ErrorViewModel.cs b/Postall/Models/ErrorViewModel.cs similarity index 100% rename from VCart/Models/ErrorViewModel.cs rename to Postall/Models/ErrorViewModel.cs diff --git a/VCart/Models/Payment.cs b/Postall/Models/Payment.cs similarity index 100% rename from VCart/Models/Payment.cs rename to Postall/Models/Payment.cs diff --git a/VCart/NewReport2.upgrade.json b/Postall/NewReport2.upgrade.json similarity index 100% rename from VCart/NewReport2.upgrade.json rename to Postall/NewReport2.upgrade.json diff --git a/VCart/Blinks.csproj b/Postall/Postall.csproj similarity index 84% rename from VCart/Blinks.csproj rename to Postall/Postall.csproj index 85fe4e3..c496931 100644 --- a/VCart/Blinks.csproj +++ b/Postall/Postall.csproj @@ -10,6 +10,14 @@ + + + + + + + + @@ -21,7 +29,6 @@ - diff --git a/VCart/Program.cs b/Postall/Program.cs similarity index 84% rename from VCart/Program.cs rename to Postall/Program.cs index acf7a95..1c88c0a 100644 --- a/VCart/Program.cs +++ b/Postall/Program.cs @@ -1,7 +1,6 @@ using Blinks.LogConfig; using Microsoft.AspNetCore.Authentication.Cookies; using Microsoft.AspNetCore.Authentication.Google; -using Microsoft.AspNetCore.Authentication.MicrosoftAccount; using Microsoft.AspNetCore.Localization; using Microsoft.AspNetCore.Mvc.Razor; using Microsoft.Extensions.Options; @@ -43,7 +42,6 @@ options => { options.DefaultAuthenticateScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultSignInScheme = CookieAuthenticationDefaults.AuthenticationScheme; - options.DefaultChallengeScheme = MicrosoftAccountDefaults.AuthenticationScheme; }) .AddCookie(options => { @@ -53,15 +51,15 @@ options => }) .AddGoogle(googleOptions => { - googleOptions.ClientId = config["Authentication:Google:ClientId"]; - googleOptions.ClientSecret = config["Authentication:Google:ClientSecret"]; + googleOptions.ClientId = builder.Configuration.GetSection("Authentication:Google:AppId").Value; + googleOptions.ClientSecret = builder.Configuration.GetSection("Authentication:Google:AppSecret").Value; + googleOptions.CallbackPath = "/signin-google"; }) -.AddMicrosoftAccount(microsoftOptions => +.AddFacebook(options => { - microsoftOptions.ClientId = config["Authentication:Microsoft:ClientId"]; - //microsoftOptions.ClientSecret = "2a7cb1bd-037a-49fa-9e5e-2b2655431af9"; - microsoftOptions.ClientSecret = config["Authentication:Microsoft:ClientSecret"]; -}) + options.AppId = builder.Configuration.GetSection("Authentication:Facebook:AppId").Value; + options.AppSecret = builder.Configuration.GetSection("Authentication:Facebook:AppSecret").Value; +}); ; builder.Services.AddLocalization(options => options.ResourcesPath = "Resources"); diff --git a/VCart/Properties/launchSettings.json b/Postall/Properties/launchSettings.json similarity index 100% rename from VCart/Properties/launchSettings.json rename to Postall/Properties/launchSettings.json diff --git a/VCart/Readme.md b/Postall/Readme.md similarity index 100% rename from VCart/Readme.md rename to Postall/Readme.md diff --git a/VCart/Resource.Designer.cs b/Postall/Resource.Designer.cs similarity index 99% rename from VCart/Resource.Designer.cs rename to Postall/Resource.Designer.cs index f184f70..4e17e68 100644 --- a/VCart/Resource.Designer.cs +++ b/Postall/Resource.Designer.cs @@ -39,7 +39,7 @@ namespace Blinks { public static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Blinks.Resource", typeof(Resource).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Postall.Resource", typeof(Resource).Assembly); resourceMan = temp; } return resourceMan; diff --git a/VCart/Resource.pt-BR.Designer.cs b/Postall/Resource.pt-BR.Designer.cs similarity index 100% rename from VCart/Resource.pt-BR.Designer.cs rename to Postall/Resource.pt-BR.Designer.cs diff --git a/VCart/Resource.pt-BR.resx b/Postall/Resource.pt-BR.resx similarity index 100% rename from VCart/Resource.pt-BR.resx rename to Postall/Resource.pt-BR.resx diff --git a/VCart/Resource.resx b/Postall/Resource.resx similarity index 100% rename from VCart/Resource.resx rename to Postall/Resource.resx diff --git a/VCart/Views/Home/Carousel1.cshtml b/Postall/Views/Home/Carousel1.cshtml similarity index 100% rename from VCart/Views/Home/Carousel1.cshtml rename to Postall/Views/Home/Carousel1.cshtml diff --git a/VCart/Views/Home/Index.cshtml b/Postall/Views/Home/Index.cshtml similarity index 100% rename from VCart/Views/Home/Index.cshtml rename to Postall/Views/Home/Index.cshtml diff --git a/VCart/Views/Home/Index.cshtml.css b/Postall/Views/Home/Index.cshtml.css similarity index 100% rename from VCart/Views/Home/Index.cshtml.css rename to Postall/Views/Home/Index.cshtml.css diff --git a/VCart/Views/Home/Privacy.cshtml b/Postall/Views/Home/Privacy.cshtml similarity index 100% rename from VCart/Views/Home/Privacy.cshtml rename to Postall/Views/Home/Privacy.cshtml diff --git a/VCart/Views/Login/Index.cshtml b/Postall/Views/Login/Index.cshtml similarity index 100% rename from VCart/Views/Login/Index.cshtml rename to Postall/Views/Login/Index.cshtml diff --git a/VCart/Views/Login/Index_xpto.css b/Postall/Views/Login/Index_xpto.css similarity index 100% rename from VCart/Views/Login/Index_xpto.css rename to Postall/Views/Login/Index_xpto.css diff --git a/Postall/Views/OtherLogins/Index.cshtml b/Postall/Views/OtherLogins/Index.cshtml new file mode 100644 index 0000000..5f2cad9 --- /dev/null +++ b/Postall/Views/OtherLogins/Index.cshtml @@ -0,0 +1,16 @@ +@{ + ViewData["Title"] = "Site"; +} + +
+

Login

+
+
+
+ +
+
+
+
diff --git a/VCart/Views/Pay/Index.cshtml b/Postall/Views/Pay/Index.cshtml similarity index 100% rename from VCart/Views/Pay/Index.cshtml rename to Postall/Views/Pay/Index.cshtml diff --git a/VCart/Views/Plans/Index.cshtml b/Postall/Views/Plans/Index.cshtml similarity index 100% rename from VCart/Views/Plans/Index.cshtml rename to Postall/Views/Plans/Index.cshtml diff --git a/VCart/Views/Plans/Index.cshtml.css b/Postall/Views/Plans/Index.cshtml.css similarity index 100% rename from VCart/Views/Plans/Index.cshtml.css rename to Postall/Views/Plans/Index.cshtml.css diff --git a/VCart/Views/Plans/OrderView.cshtml b/Postall/Views/Plans/OrderView.cshtml similarity index 100% rename from VCart/Views/Plans/OrderView.cshtml rename to Postall/Views/Plans/OrderView.cshtml diff --git a/VCart/Views/Plans/Pay - Copy.cshtml b/Postall/Views/Plans/Pay - Copy.cshtml similarity index 100% rename from VCart/Views/Plans/Pay - Copy.cshtml rename to Postall/Views/Plans/Pay - Copy.cshtml diff --git a/VCart/Views/Plans/Pay.cshtml b/Postall/Views/Plans/Pay.cshtml similarity index 100% rename from VCart/Views/Plans/Pay.cshtml rename to Postall/Views/Plans/Pay.cshtml diff --git a/VCart/Views/Shared/Error.cshtml b/Postall/Views/Shared/Error.cshtml similarity index 100% rename from VCart/Views/Shared/Error.cshtml rename to Postall/Views/Shared/Error.cshtml diff --git a/VCart/Views/Shared/_Busy.cshtml b/Postall/Views/Shared/_Busy.cshtml similarity index 100% rename from VCart/Views/Shared/_Busy.cshtml rename to Postall/Views/Shared/_Busy.cshtml diff --git a/VCart/Views/Shared/_Language.cshtml b/Postall/Views/Shared/_Language.cshtml similarity index 100% rename from VCart/Views/Shared/_Language.cshtml rename to Postall/Views/Shared/_Language.cshtml diff --git a/VCart/Views/Shared/_Layout.cshtml b/Postall/Views/Shared/_Layout.cshtml similarity index 90% rename from VCart/Views/Shared/_Layout.cshtml rename to Postall/Views/Shared/_Layout.cshtml index 3d183f9..b9bbb0b 100644 --- a/VCart/Views/Shared/_Layout.cshtml +++ b/Postall/Views/Shared/_Layout.cshtml @@ -5,11 +5,11 @@ - @ViewData["Title"] - Blinks + @ViewData["Title"] - PostAll - + @await RenderSectionAsync("Styles", required: false) @@ -17,7 +17,7 @@