Esempio n. 1
0
        public IActionResult Create([FromBody] Organisation organisationIn)
        {
            Organisation organisationToCreate = _organisationsService.Create(organisationIn);

            return(CreatedAtRoute(
                       routeName: "GetOrganisationById",
                       routeValues: new { id = organisationToCreate.Id.ToString() },
                       value: organisationToCreate));
        }
Esempio n. 2
0
 public IActionResult Add([FromBody] Organsation organisation)
 {
     try
     {
         organisationService.Create(organisation, organisationService.UserId);
         return(Ok(organisation));
     }
     catch (Exception ex)
     {
         return(BadRequest(new Error(ex.Message)));
     }
 }
Esempio n. 3
0
        public async Task <IActionResult> OnPostConfirmationAsync(string returnUrl = null)
        {
            this.Currencies = _currencyService.GetCurrencies();
            returnUrl       = returnUrl ?? Url.Content("~/");
            // Get the information about the user from the external login provider
            var info = await _signInManager.GetExternalLoginInfoAsync();

            if (info == null)
            {
                ErrorMessage = "Error loading external login information during confirmation.";
                return(RedirectToPage("./Login", new { ReturnUrl = returnUrl }));
            }

            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = Input.Email, Email = Input.Email
                };

                var result = await _userManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await _userManager.AddLoginAsync(user, info);

                    if (result.Succeeded)
                    {
                        _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);

                        var userId = await _userManager.GetUserIdAsync(user);

                        var claims = new List <Claim>
                        {
                            new Claim(ClaimTypes.Surname, Input.FirstName),
                            new Claim(ClaimTypes.GivenName, Input.LastName),
                            new Claim(ClaimTypes.MobilePhone, Input.PhoneNumber)
                        };
                        await _userManager.AddClaimsAsync(user, claims);

                        var organisation = new Organsation
                        {
                            BussinessRegistrationNumber = "",
                            Contact = new Contact
                            {
                                PhoneNumber = Input.PhoneNumber,
                                Address     = "",
                                ContactName = Input.FirstName + " " + Input.LastName,
                                Email       = Input.Email,
                                Website     = "",
                                Id          = Guid.NewGuid().ToString()
                            },
                            DeclareTax               = Input.TaxDeclare,
                            LegalLocalName           = Input.OrganisationDisplayName,
                            LegalName                = Input.OrganisationDisplayName,
                            Description              = "",
                            DisplayName              = Input.OrganisationDisplayName,
                            LineBusiness             = "",
                            LogoUrl                  = "",
                            OrganisationTypeId       = 1,
                            TaxNumber                = "",
                            OrganisationBaseCurrency = new OrganisationBaseCurrency
                            {
                                BaseCurrencyId = Input.BaseCurrencyId,
                                TaxCurrencyId  = Input.BaseCurrencyId
                            }
                        };
                        var baseCurrency = Currencies.FirstOrDefault(u => u.Id == Input.BaseCurrencyId);
                        if (Input.TaxDeclare && baseCurrency.Code != "KHR")
                        {
                            organisation.OrganisationBaseCurrency.TaxCurrencyId   = Currencies.FirstOrDefault(u => u.Code == "KHR").Id;
                            organisation.OrganisationBaseCurrency.TaxExchangeRate = 4000;
                        }
                        _organisationService.Create(organisation, user.Id);

                        var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                        code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                        var callbackUrl = Url.Page(
                            "/Account/ConfirmEmail",
                            pageHandler: null,
                            values: new { area = "Identity", userId = userId, code = code },
                            protocol: Request.Scheme);

                        await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                          $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.", true);

                        // If account confirmation is required, we need to show the link if we don't have a real email sender
                        if (_userManager.Options.SignIn.RequireConfirmedAccount)
                        {
                            return(RedirectToPage("./RegisterConfirmation", new { Email = Input.Email }));
                        }

                        await _signInManager.SignInAsync(user, isPersistent : false, info.LoginProvider);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            ProviderDisplayName = info.ProviderDisplayName;
            ReturnUrl           = returnUrl;
            return(Page());
        }
Esempio n. 4
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            Currencies     = _currencyService.GetCurrencies();
            returnUrl      = returnUrl ?? Url.Content("~/");
            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");
                    var claims = new List <Claim>();
                    claims.Add(new Claim(ClaimTypes.Surname, Input.FirstName));
                    claims.Add(new Claim(ClaimTypes.GivenName, Input.LastName));
                    claims.Add(new Claim(ClaimTypes.MobilePhone, Input.PhoneNumber));
                    user = await _userManager.FindByEmailAsync(Input.Email);

                    await _userManager.AddClaimsAsync(user, claims);

                    var organisation = new Organsation
                    {
                        BussinessRegistrationNumber = "",
                        Contact = new Contact
                        {
                            PhoneNumber = Input.PhoneNumber,
                            Address     = "",
                            ContactName = Input.FirstName + " " + Input.LastName,
                            Email       = Input.Email,
                            Website     = "",
                            Id          = Guid.NewGuid().ToString()
                        },
                        DeclareTax               = Input.TaxDeclare,
                        LegalLocalName           = Input.OrganisationDisplayName,
                        LegalName                = Input.OrganisationDisplayName,
                        Description              = "",
                        DisplayName              = Input.OrganisationDisplayName,
                        LineBusiness             = "",
                        LogoUrl                  = "",
                        OrganisationTypeId       = 1,
                        TaxNumber                = "",
                        OrganisationBaseCurrency = new OrganisationBaseCurrency
                        {
                            BaseCurrencyId = Input.BaseCurrencyId,
                            TaxCurrencyId  = Input.BaseCurrencyId
                        }
                    };
                    var baseCurrency = Currencies.FirstOrDefault(u => u.Id == Input.BaseCurrencyId);
                    if (Input.TaxDeclare && baseCurrency.Code != "KHR")
                    {
                        organisation.OrganisationBaseCurrency.TaxCurrencyId   = Currencies.FirstOrDefault(u => u.Code == "KHR").Id;
                        organisation.OrganisationBaseCurrency.TaxExchangeRate = 4000;
                    }
                    _organisationService.Create(organisation, user.Id);
                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { area = "Identity", userId = user.Id, code = code, returnUrl = returnUrl },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email", $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.", true);

                    if (_userManager.Options.SignIn.RequireConfirmedAccount)
                    {
                        return(RedirectToPage("RegisterConfirmation", new { email = Input.Email, returnUrl = returnUrl }));
                    }
                    else
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }