예제 #1
0
        public async Task <IActionResult> Edit(long id, [Bind("AccountId,AccountType,FirstName,LastName")] Account account)
        {
            if (id != account.AccountId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(account);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AccountExists(account.AccountId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(account));
        }
예제 #2
0
        public async Task <IActionResult> Edit(int id, [Bind("AccountNumber,AccountType,CustomerID,ModifyDate")] Account account)
        {
            if (id != account.AccountNumber)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(account);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AccountExists(account.AccountNumber))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerID"] = new SelectList(_context.Set <Customer>(), "CustomerID", "CustomerName", account.CustomerID);
            return(View(account));
        }
예제 #3
0
        public async Task <IActionResult> Edit(int id, [Bind("AccountNumber,CustomerName,Branch,JoiningDate")] Account account)
        {
            if (id != account.AccountNumber)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(account);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AccountExists(account.AccountNumber))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(account));
        }
        public async Task <IActionResult> Account(UsersModel model)
        {
            var updateUserAccount = await _context.UsersModel.FirstOrDefaultAsync(user => user.UserId == _userManager.GetUserId(HttpContext.User));

            updateUserAccount.FirstName   = model.FirstName;
            updateUserAccount.LastName    = model.LastName;
            updateUserAccount.DateOfBirth = model.DateOfBirth;
            updateUserAccount.Gender      = Enum.GetName(typeof(Gender), int.Parse(model.Gender));
            _context.Update(updateUserAccount);
            await _context.SaveChangesAsync();

            return(View(model));
        }
예제 #5
0
 public async Task LogIn(Account account)
 {
     account.LastLoginDateTime = DateTime.Now;
     _db.Update(account);
     await _db.SaveChangesAsync();
 }
예제 #6
0
 public void UpdateItem(Account account)
 {
     _context.Update(account);
 }
예제 #7
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <CookiePolicyOptions>(options =>
            {
                options.MinimumSameSitePolicy = SameSiteMode.None;
            });

            services.AddAuthentication(AzureADDefaults.AuthenticationScheme)
            .AddAzureAD(options => Configuration.Bind("AzureAd", options))
            .AddCookie(CookieAuthenticationDefaults.AuthenticationScheme, options =>
            {
                options.AccessDeniedPath  = "/Account/Unauthorised";
                options.ExpireTimeSpan    = TimeSpan.FromHours(1);
                options.SlidingExpiration = true;
                options.Cookie.SameSite   = SameSiteMode.Strict;
                options.EventsType        = typeof(CustomCookieAuthenticationEvents);
                options.LoginPath         = "/Landing/RealmDiscovery";
            });

            services.Configure <OpenIdConnectOptions>(AzureADDefaults.OpenIdScheme, options =>
            {
                options.Authority += "/v2.0/";
                options.TokenValidationParameters.ValidateIssuer = true;
                options.GetClaimsFromUserInfoEndpoint            = true;
                options.SkipUnrecognizedRequests = true;
                options.UseTokenLifetime         = true;
                options.RemoteSignOutPath        = "/single-signout";
                options.Events = new OpenIdConnectEvents
                {
                    OnRemoteFailure = context =>
                    {
                        context.Response.Redirect("/Landing/Unauthenticated");
                        context.HandleResponse();
                        return(Task.FromResult(0));
                    },
                    OnAuthenticationFailed = context =>
                    {
                        context.Response.Redirect("/Landing/Unauthenticated");
                        context.HandleResponse();
                        return(Task.FromResult(0));
                    },
                    OnRedirectToIdentityProvider = context =>
                    {
                        if (context.ProtocolMessage.RedirectUri.StartsWith("http://"))
                        {
                            context.ProtocolMessage.RedirectUri = context.ProtocolMessage.RedirectUri.Replace("http://", "https://");
                        }
                        if (context.Properties.Items.TryGetValue("prompt", out string prompt))
                        {
                            context.ProtocolMessage.Prompt = prompt;
                        }
                        if (context.Properties.Items.TryGetValue("login_hint", out string loginHint))
                        {
                            context.ProtocolMessage.LoginHint = loginHint;
                        }
                        return(Task.CompletedTask);
                    },
                    OnRedirectToIdentityProviderForSignOut = context =>
                    {
                        if (context.ProtocolMessage.PostLogoutRedirectUri.StartsWith("http://"))
                        {
                            context.ProtocolMessage.PostLogoutRedirectUri = context.ProtocolMessage.PostLogoutRedirectUri.Replace("http://", "https://");
                        }
                        return(Task.CompletedTask);
                    },
                    OnSignedOutCallbackRedirect = context =>
                    {
                        context.Response.Redirect("/Landing/Signout");
                        context.HandleResponse();
                        return(Task.CompletedTask);
                    },
                    OnTokenValidated = loginContext =>
                    {
                        var claimsIdentity            = (ClaimsIdentity)loginContext.Principal.Identity;
                        AccountContext accountContext = loginContext.HttpContext.RequestServices.GetRequiredService <AccountContext>();
                        User retrieved = accountContext.Users.Where(u => u.IDPReference == claimsIdentity.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value).FirstOrDefault();
                        if (retrieved != null)
                        {
                            if (!retrieved.Username.Equals(claimsIdentity.FindFirst("preferred_username").Value))
                            {
                                retrieved.Username = claimsIdentity.FindFirst("preferred_username").Value;
                            }
                            retrieved.ForceSignOut      = false;
                            retrieved.HybridSignIncount = 0;
                            foreach (var claim in claimsIdentity.Claims)
                            {
                                if (claim.Type.Equals("groups"))
                                {
                                    List <Role> retrievedRoles = accountContext.Roles.ToList();
                                    foreach (var retrievedRole in retrievedRoles)
                                    {
                                        if (retrievedRole.IDPReference.Equals(claim.Value))
                                        {
                                            retrieved.LinkedRole = retrievedRole;
                                        }
                                    }
                                }
                                else if (claim.Type.Equals(ClaimTypes.Email))
                                {
                                    retrieved.EmailAddress         = claim.Value;
                                    retrieved.VerifiedEmailAddress = true;
                                }
                                else if (claim.Type.Equals(ClaimTypes.MobilePhone))
                                {
                                    retrieved.PhoneNumber         = claim.Value;
                                    retrieved.VerifiedPhoneNumber = true;
                                }
                            }
                            if (retrieved.VerifiedEmailAddress && retrieved.VerifiedPhoneNumber)
                            {
                                retrieved.OverridableField = OverridableField.None;
                            }
                            else if (retrieved.VerifiedEmailAddress)
                            {
                                retrieved.OverridableField = OverridableField.PhoneNumber;
                            }
                            else if (retrieved.VerifiedPhoneNumber)
                            {
                                retrieved.OverridableField = OverridableField.EmailAddress;
                            }
                            retrieved.LastAuthentication = DateTime.Now;
                            accountContext.Update(retrieved);
                            accountContext.SaveChanges();
                        }
                        else
                        {
                            retrieved = accountContext.Users.Where(u => u.Username == claimsIdentity.FindFirst("preferred_username").Value).FirstOrDefault();
                            if (retrieved == null)
                            {
                                User import = new User
                                {
                                    Username           = claimsIdentity.FindFirst("preferred_username").Value,
                                    Name               = claimsIdentity.FindFirst("name").Value,
                                    Password           = Password.GetRandomSalt(),
                                    Existence          = Existence.External,
                                    IDPReference       = claimsIdentity.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value,
                                    LastPasswordChange = DateTime.Now,
                                    LastAuthentication = DateTime.Now,
                                    Status             = UserStatus.Active,
                                    OverridableField   = OverridableField.Both
                                };
                                foreach (var claim in claimsIdentity.Claims)
                                {
                                    if (claim.Type.Equals("groups"))
                                    {
                                        List <Role> retrievedRoles = accountContext.Roles.ToList();
                                        foreach (var retrievedRole in retrievedRoles)
                                        {
                                            if (retrievedRole.IDPReference.Equals(claim.Value))
                                            {
                                                import.LinkedRole = retrievedRole;
                                            }
                                        }
                                    }
                                    else if (claim.Type.Equals(ClaimTypes.Email))
                                    {
                                        import.EmailAddress         = claim.Value;
                                        import.VerifiedEmailAddress = true;
                                    }
                                    else if (claim.Type.Equals(ClaimTypes.MobilePhone))
                                    {
                                        import.PhoneNumber         = claim.Value;
                                        import.VerifiedPhoneNumber = true;
                                    }
                                }
                                if (string.IsNullOrWhiteSpace(import.EmailAddress) && claimsIdentity.FindFirst("preferred_username").Value.Contains('@'))
                                {
                                    import.EmailAddress         = claimsIdentity.FindFirst("preferred_username").Value;
                                    import.VerifiedEmailAddress = true;
                                }
                                if (import.VerifiedEmailAddress && import.VerifiedPhoneNumber)
                                {
                                    import.OverridableField = OverridableField.None;
                                }
                                else if (import.VerifiedEmailAddress)
                                {
                                    import.OverridableField = OverridableField.PhoneNumber;
                                }
                                else if (import.VerifiedPhoneNumber)
                                {
                                    import.OverridableField = OverridableField.EmailAddress;
                                }
                                accountContext.Add(import);
                                accountContext.SaveChanges();
                                import            = accountContext.Users.Where(u => u.IDPReference == claimsIdentity.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value).FirstOrDefault();
                                Settings settings = new Settings
                                {
                                    LinkedUserID = import.ID,
                                    LinkedUser   = import
                                };
                                if (import.VerifiedEmailAddress == true)
                                {
                                    settings.CommmuicationOptions = CommmuicationOptions.EMAIL;
                                }
                                else if (import.VerifiedPhoneNumber == true || import.OverridableField == OverridableField.None)
                                {
                                    settings.CommmuicationOptions = CommmuicationOptions.SMS;
                                }
                                accountContext.Settings.Add(settings);
                                accountContext.SaveChanges();
                            }
                            else
                            {
                                loginContext.Response.Redirect("/Landing/Unauthenticated");
                                loginContext.HandleResponse();
                                return(Task.FromResult(0));
                            }
                        }
                        foreach (var claim in claimsIdentity.Claims.ToList())
                        {
                            if (claim.Type.Equals("groups"))
                            {
                                List <Role> retrievedRoles = accountContext.Roles.ToList();
                                foreach (var retrievedRole in retrievedRoles)
                                {
                                    if (retrievedRole.IDPReference.Equals(claim.Value))
                                    {
                                        claimsIdentity.AddClaim(new Claim(ClaimTypes.Role, retrievedRole.RoleName));
                                    }
                                }
                            }
                        }
                        if (claimsIdentity.FindFirst("http://schemas.microsoft.com/identity/claims/identityprovider") == null)
                        {
                            claimsIdentity.AddClaim(new Claim("http://schemas.microsoft.com/identity/claims/identityprovider", claimsIdentity.FindFirst("iss").Value.Remove(claimsIdentity.FindFirst("iss").Value.Length - 4)));
                        }
                        return(Task.FromResult(0));
                    }
                };
            });
 public AccountDomain Update(AccountDomain domain)
 {
     return(_context
            .Update(domain)
            .Entity);
 }
 public async Task UpdateSistema(Sistema sistema)
 {
     _accountContext.Update(sistema);
     await _accountContext.SaveChangesAsync();
 }
예제 #10
0
        /// <summary>
        /// Generic Update() method to update information in the database
        /// </summary>
        /// <param name="entity">Entity object being updated</param>
        /// <returns>Return Object entity updated</returns>
        public async virtual Task <T> Update(T entity)
        {
            var ent = _context.Update(entity).Entity;

            return(ent);
        }