コード例 #1
0
ファイル: ExtraMethods.cs プロジェクト: brinq-africa/kaedc
        public static void AddProfit(Kaedcuser user, Transaction transaction)
        {
            Transaction profitTransacton = new Transaction();
            Kaedc       db = new Kaedc();

            var          amount     = transaction.Amount;
            const double commission = 0.005;
            double       profit     = 0.0;

            if (transaction.ServiceId == 1)
            {
                profit = transaction.Amount * commission;
            }
            user.MainBalance += Convert.ToDecimal(profit);


            profitTransacton.Id                  = GenerateId();
            profitTransacton.ServiceId           = 6;
            profitTransacton.AgentProfit         = Convert.ToDecimal(profit);
            profitTransacton.Amount              = profit;
            profitTransacton.PayersName          = user.UserName;
            profitTransacton.PaymentMethodId     = 1;
            profitTransacton.transactionsStatus  = "completed";
            profitTransacton.Datetime            = DateTime.Now;
            profitTransacton.KaedcUserNavigation = user;
            //profitTransacton.Service = db.Service.Where(s => s.Id == 6).FirstOrDefault();

            db.Add(profitTransacton);
        }
コード例 #2
0
        private async Task CreateRoles(IServiceProvider serviceProvider)
        {
            //initializing custom roles
            var RoleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >();
            var UserManager = serviceProvider.GetRequiredService <UserManager <Kaedcuser> >();

            string[]       roleNames = { "SuperAdmin", "Admin", "Manager", "Agent", "Member" };
            IdentityResult roleResult;

            foreach (var roleName in roleNames)
            {
                var roleExist = await RoleManager.RoleExistsAsync(roleName);

                if (!roleExist)
                {
                    //create the roles and seed them to the database: Question 1
                    roleResult = await RoleManager.CreateAsync(new IdentityRole(roleName));
                }
            }

            //Assigning SuperAdmin role to the main User here we have given our newly registered
            //login id for SuperAdmin management
            Kaedcuser user = await UserManager.FindByEmailAsync("*****@*****.**");

            await UserManager.AddToRoleAsync(user, "SuperAdmin");
        }
コード例 #3
0
        public async Task <IActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = new Kaedcuser()
            {
                UserName    = model.Username, Email = model.Email, Firstname = model.Firstname, Surname = model.Surname,
                MainBalance = 0, IsActive = 1, LoanBalance = 0, BrinqaccountNumber = GenerateAccountNumber(model), PhoneNumber = model.PhoneNumber, CreatedAt = DateTime.Now
            };

            var result = await _userManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return(BadRequest(new {
                    result,
                    status = StatusCode(400)
                }));
            }

            var claims = new[]
            {
                //new Claim(JwtRegisteredClaimNames.Sub, user.Email),
                //new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString())
                new Claim(ClaimTypes.Name, user.Email),
                new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
            };

            var signingkey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes("LongSecuritySecureKey"));

            var token = new JwtSecurityToken(
                issuer: "https://www.brinqkaedc.com",
                audience: "https://www.brinqkaedc.com",
                expires: DateTime.UtcNow.AddYears(1),
                claims: claims,
                signingCredentials: new SigningCredentials(signingkey, SecurityAlgorithms.HmacSha256)
                );

            return(Ok(new { result,
                            Token = new JwtSecurityTokenHandler().WriteToken(token),
                            Expiration = token.ValidTo,
                            user.BrinqaccountNumber,
                            user.MainBalance,
                            user.IsActive,
                            user.Firstname,
                            user.Surname,
                            user.Email,
                            user.PhoneNumber, Status = StatusCode(200) }));
        }
コード例 #4
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                //var user = new Kaedcuser { UserName = Input.Email, Email = Input.Email };
                var user = new Kaedcuser()
                {
                    UserName           = Input.Username,
                    Email              = Input.Email,
                    Firstname          = Input.Firstname,
                    Surname            = Input.Surname,
                    MainBalance        = Convert.ToInt64(Input.Mainbalance),
                    IsActive           = 1,
                    LoanBalance        = 0,
                    BrinqaccountNumber = GenerateAccountNumber(),
                    PhoneNumber        = Input.PhoneNumber
                };

                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, 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>.");

                    await _userManager.AddToRoleAsync(user, Input.Role);

                    //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
            ViewData["Roles"] = new SelectList(db.Roles, "Name", "Name");
            return(Page());
        }
コード例 #5
0
        private async Task LoadSharedKeyAndQrCodeUriAsync(Kaedcuser user)
        {
            // Load the authenticator key & QR code URI to display on the form
            var unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);

            if (string.IsNullOrEmpty(unformattedKey))
            {
                await _userManager.ResetAuthenticatorKeyAsync(user);

                unformattedKey = await _userManager.GetAuthenticatorKeyAsync(user);
            }

            SharedKey = FormatKey(unformattedKey);

            var email = await _userManager.GetEmailAsync(user);

            AuthenticatorUri = GenerateQrCodeUri(email, unformattedKey);
        }
コード例 #6
0
        public async Task <IActionResult> OnPostConfirmationAsync(string returnUrl = null)
        {
            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 Kaedcuser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user);

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

                    if (result.Succeeded)
                    {
                        await _signInManager.SignInAsync(user, isPersistent : false);

                        _logger.LogInformation("User created an account using {Name} provider.", info.LoginProvider);
                        return(LocalRedirect(returnUrl));
                    }
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            LoginProvider = info.LoginProvider;
            ReturnUrl     = returnUrl;
            return(Page());
        }
コード例 #7
0
        public IActionResult Update([FromRoute] string ID)
        {
            // Get the model
            Kaedcuser model = db.Kaedcuser.Where(m => m.Id == ID).FirstOrDefault();

            // Update properties
            //model.timestamp = DateTime.UtcNow;
            //model.applied_by = System.Web.HttpContext.Current.User.Identity.Name;
            //model.status = "Done";
            if (model.IsActive == 0)
            {
                model.IsActive = 1;
            }
            else
            {
                model.IsActive = 0;
            }


            // Save and redirect
            db.Entry(model).State = EntityState.Modified;
            db.SaveChanges();
            return(RedirectToAction("customerList"));
        }