示例#1
0
        public Result DeleteEvent(int id, int?userId = null)
        {
            var entity = _calenderDal.Get(s => s.Id == id);

            if (entity == null)
            {
                return new Result
                       {
                           Message = "Veri Bulunamadı",
                           Success = false
                       }
            }
            ;

            userId = userId ?? AuthenticateHelper.AuthenticateUserId();
            if (entity.UserId != userId)
            {
                return new Result
                       {
                           Message = "Bu Veriyi Silme Yetkiniz Yok",
                           Success = false
                       }
            }
            ;

            _calenderDal.Delete(entity);
            return(new Result
            {
                Message = "Veri Silindi",
                Success = true
            });
        }
    }
}
示例#2
0
        public Result UpdateEvent(PostUserCalenderUpdateTypeModel model, int?userId = null)
        {
            var entity = _calenderDal.Get(s => s.Id == model.Id);

            if (entity == null)
            {
                return new Result
                       {
                           Message = "Veri Bulunamadı",
                           Success = false
                       }
            }
            ;

            userId = userId ?? AuthenticateHelper.AuthenticateUserId();
            if (entity.UserId != userId)
            {
                return new Result
                       {
                           Message = "Bu Veriyi Düzenleme Yetkiniz Yok",
                           Success = false
                       }
            }
            ;

            entity.RecordType = model.RecordType;
            _calenderDal.Update(entity);

            return(new Result
            {
                Message = "Veri Düzenlendi",
                Success = true
            });
        }
        public ActionResult Index([ModelBinder(typeof(UserDataModelBinder))] string userData)
        {
            var tuple = UserLoginHelper.GetUserData(userData);

            AuthenticateHelper.SetTicket(tuple.Item1.ToString(), null, 0, tuple.Item2);

            return(Redirect("/Home/Index"));
        }
示例#4
0
 protected void btnlogin_ServerClick(object sender, EventArgs e)
 {
     if (!AuthenticateHelper.Login(inputusername.Value, inputpwd.Value, false, Response))
     {
         Response.Redirect("~/login.aspx");
     }
     else
     {
         LoadControl();
     }
 }
示例#5
0
        public Result UserEvents(int?userId = null)
        {
            var id = userId ?? AuthenticateHelper.AuthenticateUserId();

            return(new Result
            {
                Message = "Görev Listesi",
                Success = true,
                Data = _mapper.Map <List <GetUserCalenderModel> >(_calenderDal.GetList(s => s.UserId == id))
            });
        }
示例#6
0
        private async void OKbutton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (!String.IsNullOrEmpty(subscriptionComboBox.Text) && !String.IsNullOrEmpty(resourceGroupcomboBox.Text) && !String.IsNullOrEmpty(storageAccountcomboBox.Text))
                {
                    if (storageAccountcomboBox.SelectedItem == null)
                    {
                        var subObject          = (AutomationISEClient.SubscriptionObject)subscriptionComboBox.SelectedItem;
                        var azureARMAuthResult = AuthenticateHelper.RefreshTokenByAuthority(subObject.Authority, Properties.Settings.Default.appIdURI);
                        var authToken          = azureARMAuthResult.AccessToken;
                        var token = new Microsoft.Rest.TokenCredentials(authToken);
                        var storageManagementClient = new Microsoft.Azure.Management.Storage.StorageManagementClient(new Uri(Properties.Settings.Default.appIdURI), token);
                        storageManagementClient.SubscriptionId = subObject.SubscriptionId;
                        var result = await storageManagementClient.StorageAccounts.CheckNameAvailabilityAsync(storageAccountcomboBox.Text);

                        if (!(result.NameAvailable.Value))
                        {
                            var messageBoxResult = System.Windows.Forms.MessageBox.Show(
                                "Storage account name is not available in this subscription. Please choose another name", "Name not available",
                                System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Warning);
                        }
                        else
                        {
                            createNewStorageAccount  = true;
                            storageSubID             = ((AutomationISEClient.SubscriptionObject)subscriptionComboBox.SelectedItem).SubscriptionId;
                            storageResourceGroupName = resourceGroupcomboBox.Text;
                            storageAccountName       = storageAccountcomboBox.Text;
                            region            = regionComboBox.Text;
                            this.DialogResult = true;
                            this.Close();
                        }
                    }
                    else
                    {
                        storageSubID             = ((AutomationISEClient.SubscriptionObject)subscriptionComboBox.SelectedItem).SubscriptionId;
                        storageResourceGroupName = resourceGroupcomboBox.SelectedItem.ToString();
                        storageAccountName       = storageAccountcomboBox.Text;
                        this.DialogResult        = true;
                        this.Close();
                    }
                }
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }
示例#7
0
        public IActionResult Login([FromBody] UserJwt login)
        {
            IActionResult response = Unauthorized();
            UserJwt       user     = AuthenticateHelper.AuthenticateUser(login);

            if (user != null)
            {
                var tokenString = AuthenticateHelper.GenerateJWTToken(user, _config);
                response = Ok(new
                {
                    token       = tokenString,
                    userDetails = user,
                });
            }
            return(response);
        }
示例#8
0
        public Result CreateEvent(PostUserCalenderModel model, int?userId = null)
        {
            userId = userId ?? AuthenticateHelper.AuthenticateUserId();
            var entity = _mapper.Map <UserCalender>(model);

            entity.UserId = (int)userId;

            var turnData = _calenderDal.Add(entity);

            return(new Result
            {
                Success = true,
                Message = "Kayıt Başarılı",
                Data = _mapper.Map <GetUserCalenderModel>(turnData)
            });
        }
        public ActionResult LoginPost(string userName, string password)
        {
            if (userName.IsNullOrEmpty() || password.IsNullOrEmpty())
            {
                return(Redirect("/login/index"));
            }

            var tuple = Application.ApplicationRegistry.User.Login(userName, password);

            if (tuple == null)
            {
                return(Redirect("/login/index"));
            }
            AuthenticateHelper.SetTicket(tuple.Item1.ToString(), null, 0, tuple.Item2);

            return(Redirect("/home/index"));
        }
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            var request = filterContext.HttpContext.Request;
            AuthenticateUserTicket ticket = AuthenticateHelper.AuthenticateTicket();

            if (ticket != null && !ticket.Expired)
            {
                if (request.AppRelativeCurrentExecutionFilePath.ToUpper() == AuthenticateHelper.LoginUrl.ToUpper())
                {//已经登录则不能再进入登录页面
                    filterContext.Result = new RedirectResult(AuthenticateHelper.LoginRedirectPage);
                    return;
                }
                filterContext.HttpContext.User = new AuthenticateUser(ticket);
            }
            else
            {
                filterContext.Result = new RedirectResult(AuthenticateHelper.LoginUrl);
            }
        }
        public AuthenticateHelperFixture(ITestOutputHelper outputHelper)
        {
            _clientRepositoryStub = new Mock <IClientStore>();
            _consentRepository    = new Mock <IConsentRepository>();
            var scopeRepository = new Mock <IScopeRepository>();

            scopeRepository.Setup(x => x.SearchByNames(It.IsAny <CancellationToken>(), It.IsAny <string[]>()))
            .ReturnsAsync(new[] { new Scope {
                                      Name = "scope"
                                  } });
            _authenticateHelper = new AuthenticateHelper(
                new Mock <IAuthorizationCodeStore>().Object,
                new Mock <ITokenStore>().Object,
                scopeRepository.Object,
                _consentRepository.Object,
                _clientRepositoryStub.Object,
                new InMemoryJwksRepository(),
                new NoopEventPublisher(),
                new TestOutputLogger("test", outputHelper));
        }
示例#12
0
        private async void subscriptionComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var subObject          = (AutomationISEClient.SubscriptionObject)subscriptionComboBox.SelectedItem;
            var azureARMAuthResult = AuthenticateHelper.RefreshTokenByAuthority(subObject.Authority, Properties.Settings.Default.appIdURI);

            authority = subObject.Authority;
            var authToken = azureARMAuthResult.AccessToken;
            var token     = new Microsoft.Rest.TokenCredentials(authToken);
            var storageManagementClient = new Microsoft.Azure.Management.Storage.StorageManagementClient(new Uri(Properties.Settings.Default.appIdURI), token);

            storageManagementClient.SubscriptionId = subObject.SubscriptionId;
            resourceGroupcomboBox.Items.Clear();
            try
            {
                storageAccounts = storageManagementClient.StorageAccounts.List();
                foreach (var storageAccount in storageAccounts)
                {
                    var startPosition = storageAccount.Id.IndexOf("/resourceGroups/");
                    var endPosition   = storageAccount.Id.IndexOf("/", startPosition + 16);
                    var resourceGroup = storageAccount.Id.Substring(startPosition + 16, endPosition - startPosition - 16);
                    if (resourceGroupcomboBox.Items.IndexOf(resourceGroup) == -1)
                    {
                        resourceGroupcomboBox.Items.Add(resourceGroup);
                    }
                }
                var cloudtoken                = AuthenticateHelper.RefreshTokenByAuthority(authority, Properties.Settings.Default.appIdURI);
                var subscriptionCreds         = new TokenCloudCredentials(((AutomationISEClient.SubscriptionObject)subscriptionComboBox.SelectedItem).SubscriptionId, cloudtoken.AccessToken);
                var resourceManagementClient  = new Microsoft.Azure.Subscriptions.SubscriptionClient(subscriptionCreds, new Uri(Properties.Settings.Default.appIdURI));
                CancellationToken cancelToken = new CancellationToken();
                var subscriptionRegions       = await resourceManagementClient.Subscriptions.ListLocationsAsync(((AutomationISEClient.SubscriptionObject)subscriptionComboBox.SelectedItem).SubscriptionId, cancelToken);

                regionComboBox.ItemsSource       = subscriptionRegions.Locations;
                regionComboBox.DisplayMemberPath = "Name";
            }
            catch (Exception Ex)
            {
                throw Ex;
            }
        }
示例#13
0
        public async Task <CustomerAuthViewModel> AuthenticateAsync(string email, string password)
        {
            var passwordHashed = AuthenticateHelper.HashPassword(password);
            var customer       = await _customerRepository.AuthenticateCustomerAsync(email, passwordHashed);

            if (customer == null)
            {
                return(null);
            }
            var claims = new Claim[]
            {
                new Claim(ClaimTypes.NameIdentifier, customer.Id.ToString()),
                new Claim(ClaimTypes.Name, email),
                new Claim("Scope", "Customer")
            };
            var jwtResult = _jwtAuthManager.GenerateTokens(email, claims, DateTime.Now);

            return(new CustomerAuthViewModel
            {
                Customer = customer,
                JwtResult = jwtResult
            });
        }
        /// <summary>
        /// Determine if there is a valid context stored in ASP.Net <see cref="HttpContext"/>
        /// </summary>
        /// <returns></returns>
        public static bool IsValid()
        {
            HttpContext currentContext = HttpContext.Current;

            if (currentContext != null && currentContext.Session != null)
            {
                var contextContainer = currentContext.Session[Provider] as SoContextContainer;


                // If this is a Anonymous user, we don't have a contextContainer since we actually don't need to store that data.
                if (contextContainer == null &&
                    SoContext.CurrentPrincipal != null &&
                    SoContext.CurrentPrincipal.UserType == UserType.AnonymousAssociate)
                {
                    return(true);
                }

                return(AuthenticateHelper.IsAuthenticatedWithNetServer());
            }
            else
            {
                return(false);
            }
        }
示例#15
0
        public MapperProfile()
        {
            CreateMap <ManagerInfoRequest, Manager>()
            .ForMember(m => m.Password_Hash, rq => rq.MapFrom(rq => AuthenticateHelper.HashPassword(rq.Password)))
            .ForMember(m => m.Role_Id, rq => rq.MapFrom(rq => rq.RoleId));

            CreateMap <CustomerInfoRequest, Customer>()
            .ForMember(m => m.Password_Hash, rq => rq.MapFrom(rq => AuthenticateHelper.HashPassword(rq.Password)));

            CreateMap <CategoryInfoRequest, Category>();

            CreateMap <ProductInfoRequest, Product>()
            .ForMember(p => p.Regular_Price, rq => rq.MapFrom(rq => rq.RegularPrice))
            .ForMember(p => p.Discount_Price, rq => rq.MapFrom(rq => rq.DiscountPrice));

            CreateMap <ProductCategoryViewModel, ProductViewModel>()
            .ForMember(p => p.Id, pc => pc.MapFrom(pc => pc.Product_Id))
            .ForMember(p => p.Name, pc => pc.MapFrom(pc => pc.Product_Name))
            .ForMember(p => p.Created_At, pc => pc.MapFrom(pc => pc.Created_At))
            .ForMember(p => p.Discount_Price, pc => pc.MapFrom(pc => pc.Discount_Price))
            .ForMember(p => p.Regular_Price, pc => pc.MapFrom(pc => pc.Regular_Price))
            .ForMember(p => p.Updated_At, pc => pc.MapFrom(pc => pc.Updated_At))
            .ForMember(p => p.Categories, pc => pc.Ignore());

            CreateMap <ProductCategoryViewModel, CategoryViewModel>()
            .ForMember(c => c.Id, pc => pc.MapFrom(pc => pc.Category_Id))
            .ForMember(c => c.Name, pc => pc.MapFrom(pc => pc.Category_Name))
            .ForMember(c => c.Created_At, pc => pc.MapFrom(pc => pc.Category_Created_At))
            .ForMember(c => c.Products, pc => pc.Ignore());

            _ = CreateMap <IGrouping <int, ProductCategoryViewModel>, CategoryViewModel>()
                .ForMember(c => c.Id, gr => gr.MapFrom(gr => gr.Key))
                .ForMember(c => c.Name, gr => gr.MapFrom(gr => gr.First().Category_Name))
                .ForMember(c => c.Created_At, gr => gr.MapFrom(gr => gr.First().Category_Created_At))
                //.ForMember(c => c.Products, gr => gr.MapFrom(gr => gr.ToList()));
                .ForMember(c => c.Products, gr => gr.MapFrom(gr => gr.First().Product_Name == null ? new List <ProductCategoryViewModel>() : gr.ToList()));

            CreateMap <IGrouping <int, ProductCategoryViewModel>, ProductViewModel>()
            .ForMember(p => p.Id, gr => gr.MapFrom(gr => gr.Key))
            .ForMember(p => p.Name, gr => gr.MapFrom(gr => gr.First().Product_Name))
            .ForMember(p => p.Regular_Price, gr => gr.MapFrom(gr => gr.First().Regular_Price))
            .ForMember(p => p.Discount_Price, gr => gr.MapFrom(gr => gr.First().Discount_Price))
            .ForMember(p => p.Created_At, gr => gr.MapFrom(gr => gr.First().Created_At))
            .ForMember(p => p.Updated_At, gr => gr.MapFrom(gr => gr.First().Updated_At))
            //.ForMember(p => p.Categories, gr => gr.MapFrom(gr => gr.ToList()));
            .ForMember(p => p.Categories, gr => gr.MapFrom(gr => gr.First().Category_Name == null ? new List <ProductCategoryViewModel>() : gr.ToList()));


            CreateMap <CategoryViewModel, Category>();

            CreateMap <ProductViewModel, OrderItemsViewModel>()
            .ForMember(oi => oi.Product_Id, p => p.MapFrom(p => p.Id))
            .ForMember(oi => oi.Quantity, p => p.MapFrom(p => p.Quantity))
            .ForMember(oi => oi.Item_Price, p => p.MapFrom(p => p.Quantity * (p.Regular_Price - p.Discount_Price)));

            CreateMap <OrderItemsViewModel, OrderItems>().ReverseMap();

            CreateMap <ProductViewModel, OrderItems>()
            .ForMember(oi => oi.Product_Id, p => p.MapFrom(p => p.Id))
            .ForMember(oi => oi.Quantity, p => p.MapFrom(p => p.Quantity))
            .ForMember(oi => oi.Item_Price, p => p.MapFrom(p => p.Regular_Price - p.Discount_Price));
        }
示例#16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AuthenticateController"/> class.
        /// </summary>
        /// <param name="smsClient">The SMS client.</param>
        /// <param name="dataProtectionProvider">The data protection provider.</param>
        /// <param name="urlHelperFactory">The URL helper factory.</param>
        /// <param name="actionContextAccessor">The action context accessor.</param>
        /// <param name="eventPublisher">The event publisher.</param>
        /// <param name="authorizationCodeStore">The authorization code store.</param>
        /// <param name="authenticationService">The authentication service.</param>
        /// <param name="authenticationSchemeProvider">The authentication scheme provider.</param>
        /// <param name="twoFactorAuthenticationHandler">The two factor authentication handler.</param>
        /// <param name="subjectBuilder">The subject builder.</param>
        /// <param name="consentRepository">The consent repository.</param>
        /// <param name="scopeRepository">The scope repository.</param>
        /// <param name="tokenStore">The token store.</param>
        /// <param name="resourceOwnerRepository">The resource owner repository.</param>
        /// <param name="confirmationCodeStore">The confirmation code store.</param>
        /// <param name="clientStore">The client store.</param>
        /// <param name="jwksStore">The JWKS store.</param>
        /// <param name="accountFilters">The account filters.</param>
        /// <param name="logger">The controller logger.</param>
        /// <param name="runtimeSettings">The runtime settings.</param>
        public AuthenticateController(
            ISmsClient smsClient,
            IDataProtectionProvider dataProtectionProvider,
            IUrlHelperFactory urlHelperFactory,
            IActionContextAccessor actionContextAccessor,
            IEventPublisher eventPublisher,
            IAuthorizationCodeStore authorizationCodeStore,
            IAuthenticationService authenticationService,
            IAuthenticationSchemeProvider authenticationSchemeProvider,
            ITwoFactorAuthenticationHandler twoFactorAuthenticationHandler,
            ISubjectBuilder subjectBuilder,
            IConsentRepository consentRepository,
            IScopeRepository scopeRepository,
            ITokenStore tokenStore,
            IResourceOwnerRepository resourceOwnerRepository,
            IConfirmationCodeStore confirmationCodeStore,
            IClientStore clientStore,
            IJwksStore jwksStore,
            IEnumerable <IAccountFilter> accountFilters,
            ILogger <AuthenticateController> logger,
            RuntimeSettings runtimeSettings)
            : base(
                dataProtectionProvider,
                urlHelperFactory,
                actionContextAccessor,
                eventPublisher,
                authenticationService,
                authenticationSchemeProvider,
                twoFactorAuthenticationHandler,
                authorizationCodeStore,
                consentRepository,
                scopeRepository,
                tokenStore,
                resourceOwnerRepository,
                confirmationCodeStore,
                clientStore,
                jwksStore,
                subjectBuilder,
                accountFilters,
                logger,
                runtimeSettings)
        {
            _eventPublisher        = eventPublisher;
            _confirmationCodeStore = confirmationCodeStore;
            _logger           = logger;
            _getUserOperation = new GetUserOperation(resourceOwnerRepository, logger);
            var generateSms = new GenerateAndSendSmsCodeOperation(smsClient, confirmationCodeStore, logger);

            _smsAuthenticationOperation = new SmsAuthenticationOperation(
                runtimeSettings,
                smsClient,
                confirmationCodeStore,
                resourceOwnerRepository,
                subjectBuilder,
                accountFilters.ToArray(),
                eventPublisher,
                logger);
            _validateConfirmationCode = new ValidateConfirmationCodeAction(confirmationCodeStore);
            _authenticateHelper       = new AuthenticateHelper(
                authorizationCodeStore,
                tokenStore,
                scopeRepository,
                consentRepository,
                clientStore,
                jwksStore,
                eventPublisher,
                logger);
            _generateAndSendSmsCodeOperation = generateSms;
        }
 public ActionResult Logout()
 {
     AuthenticateHelper.DestroyTicket();
     return(Redirect("/login/index"));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="BaseAuthenticateController"/> class.
 /// </summary>
 /// <param name="dataProtectionProvider">The data protection provider.</param>
 /// <param name="urlHelperFactory">The URL helper factory.</param>
 /// <param name="actionContextAccessor">The action context accessor.</param>
 /// <param name="eventPublisher">The event publisher.</param>
 /// <param name="authenticationService">The authentication service.</param>
 /// <param name="authenticationSchemeProvider">The authentication scheme provider.</param>
 /// <param name="twoFactorAuthenticationHandler">The two factor authentication handler.</param>
 /// <param name="authorizationCodeStore">The authorization code store.</param>
 /// <param name="consentRepository">The consent repository.</param>
 /// <param name="scopeRepository">The scope repository.</param>
 /// <param name="tokenStore">The token store.</param>
 /// <param name="resourceOwnerRepository">The resource owner repository.</param>
 /// <param name="confirmationCodeStore">The confirmation code store.</param>
 /// <param name="clientStore">The client store.</param>
 /// <param name="jwksStore"></param>
 /// <param name="subjectBuilder"></param>
 /// <param name="accountFilters">The account filters.</param>
 /// <param name="logger">The controller logger.</param>
 /// <param name="runtimeSettings">The runtime settings.</param>
 protected BaseAuthenticateController(
     IDataProtectionProvider dataProtectionProvider,
     IUrlHelperFactory urlHelperFactory,
     IActionContextAccessor actionContextAccessor,
     IEventPublisher eventPublisher,
     IAuthenticationService authenticationService,
     IAuthenticationSchemeProvider authenticationSchemeProvider,
     ITwoFactorAuthenticationHandler twoFactorAuthenticationHandler,
     IAuthorizationCodeStore authorizationCodeStore,
     IConsentRepository consentRepository,
     IScopeRepository scopeRepository,
     ITokenStore tokenStore,
     IResourceOwnerRepository resourceOwnerRepository,
     IConfirmationCodeStore confirmationCodeStore,
     IClientStore clientStore,
     IJwksStore jwksStore,
     ISubjectBuilder subjectBuilder,
     IEnumerable <IAccountFilter> accountFilters,
     ILogger logger,
     RuntimeSettings runtimeSettings)
     : base(authenticationService)
 {
     _generateAndSendCode = new GenerateAndSendCodeAction(
         resourceOwnerRepository,
         confirmationCodeStore,
         twoFactorAuthenticationHandler,
         logger);
     _validateConfirmationCode = new ValidateConfirmationCodeAction(confirmationCodeStore);
     _authenticateHelper       = new AuthenticateHelper(
         authorizationCodeStore,
         tokenStore,
         scopeRepository,
         consentRepository,
         clientStore,
         jwksStore,
         eventPublisher,
         logger);
     _authenticateResourceOwnerOpenId = new AuthenticateResourceOwnerOpenIdAction(
         authorizationCodeStore,
         tokenStore,
         scopeRepository,
         consentRepository,
         clientStore,
         jwksStore,
         eventPublisher,
         logger);
     DataProtector   = dataProtectionProvider.CreateProtector("Request");
     _urlHelper      = urlHelperFactory.GetUrlHelper(actionContextAccessor.ActionContext !);
     _eventPublisher = eventPublisher;
     _authenticationSchemeProvider = authenticationSchemeProvider;
     _addUser = new AddUserOperation(
         runtimeSettings,
         resourceOwnerRepository,
         accountFilters,
         subjectBuilder,
         eventPublisher);
     _getUserOperation               = new GetUserOperation(resourceOwnerRepository, logger);
     _updateUserClaimsOperation      = new UpdateUserClaimsOperation(resourceOwnerRepository, logger);
     _runtimeSettings                = runtimeSettings;
     _twoFactorAuthenticationHandler = twoFactorAuthenticationHandler;
     _resourceOwnerRepository        = resourceOwnerRepository;
     _confirmationCodeStore          = confirmationCodeStore;
     _logger = logger;
 }