// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddScoped <IAuthenticationService, AuthenticationService>(); services.AddScoped <IUserService, UserService>(); services.AddScoped <IUcretService, UcretService>(); services.AddScoped <IIsciService, IsciService>(); services.AddScoped <IAileService, AileService>(); services.AddScoped <IGrupService, GrupService>(); services.AddScoped <IGiderService, GiderService>(); services.AddScoped <IIsIsciService, IsIsciService>(); services.AddScoped(typeof(ISumService <>), typeof(SumService <>)); services.AddScoped <IIsService, IsService>(); services.AddScoped <IIsverenService, IsverenService>(); services.AddScoped <ITokenService, CustomTokenService>(); services.AddScoped(typeof(IGenericRepository <>), typeof(GenericRepository <>)); services.AddScoped(typeof(IServiceGeneric <,>), typeof(ServicesGeneric <,>)); services.AddScoped <IUnitOfWork, UnitOfWork>(); //FluentValidation Serrvisini AddFluetValidation ile uygulamaya entegre edecez //Entitlere gelen validationlarýn nerde tututulduðunu sisteme bildirmemiz lazým //RegisterValidatorsFromAssemblyContaining içinde tanýmladýðýmýz sýnýf neyse o sýnýfýn içinde bulunduðu //Asembly bulup o asembly içerisindeki tüm validater larý bulup sisteme entegre edicek services.AddControllers().AddFluentValidation(x => x.RegisterValidatorsFromAssemblyContaining <Startup>()); services.AddDbContext <ApplicationDbContext>(options => { options.UseSqlServer(Configuration.GetConnectionString("DefaultConnectionString"), sqlOptions => { sqlOptions.MigrationsAssembly("ITS.DATA"); }); }); services.AddIdentity <Cavus, IdentityRole>(opt => { opt.Password.RequiredLength = 4; opt.Password.RequireNonAlphanumeric = false; opt.Password.RequireUppercase = false; opt.Password.RequireLowercase = false; opt.Password.RequireDigit = false; } ).AddEntityFrameworkStores <ApplicationDbContext>(); services.Configure <CustomTokenOptions>(Configuration.GetSection("TokenAyar")); services.AddAuthentication(options => { options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }).AddJwtBearer(JwtBearerDefaults.AuthenticationScheme, opts => { var tokenOptionss = Configuration.GetSection("TokenAyar").Get <CustomTokenOptions>(); opts.TokenValidationParameters = new Microsoft.IdentityModel.Tokens.TokenValidationParameters() { ValidIssuer = tokenOptionss.Issuer, ValidAudience = tokenOptionss.Audience[0], IssuerSigningKey = CustomSecurity.GetSymetricSecurityKey(tokenOptionss.SecuritKey), ValidateIssuerSigningKey = true, ValidateAudience = true, ValidateIssuer = true, ClockSkew = TimeSpan.Zero }; }); }
public TokenDto CreateToken(Cavus cavus) { var AccesTokenOmru = DateTime.Now.AddMinutes(_customTokenOptions.AccesTokenO); //Token ömrünü al var RefreshTokenOmru = DateTime.Now.AddMinutes(_customTokenOptions.RefreshTokenO); //Refresh token ömrünü al var SecuritKey = CustomSecurity.GetSymetricSecurityKey(_customTokenOptions.SecuritKey); SigningCredentials signingCredentials = new SigningCredentials(SecuritKey, SecurityAlgorithms.HmacSha256Signature); //imzamızı oluşturuyoruz JwtSecurityToken jwtSecurityToken = new JwtSecurityToken( issuer: _customTokenOptions.Issuer, expires: AccesTokenOmru, notBefore: DateTime.Now, claims: GetClaim(cavus, _customTokenOptions.Audience), signingCredentials: signingCredentials); var handler = new JwtSecurityTokenHandler(); var token = handler.WriteToken(jwtSecurityToken); var tokenDto = new TokenDto { AccessToken = token, RefreshToken = CreateRefreshToken(), AccesTokenLifeTime = AccesTokenOmru, RefreshTokenLifeTime = RefreshTokenOmru }; return(tokenDto); }
public ActionResult Login(string userName, string password) { if (CustomSecurity.LogIn(userName, password)) { return(RedirectToAction("Sum", "Home")); } return(View()); }
public bool CheckLogin(string userid, string password) { bool success = false; string strAdmin = AppSettingsUtility.GetString(AppSettingsKeys.LoginRebuild); //admin string strPass = AppSettingsUtility.GetString(AppSettingsKeys.PasswordRebuild); //tsmadmin if (userid.Trim() == CustomSecurity.DecryptString(strAdmin, "webspiders")) { if (password == CustomSecurity.DecryptString(strPass, "webspiders")) { Session["LoginValidate"] = "1"; success = true; successLogin = true; } } return(success); }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { var controller = filterContext.RouteData.Values["controller"].ToString(); var action = filterContext.RouteData.Values["action"].ToString(); if (CustomSecurity.UserIsInRole(controller, action)) { } else { var basecookie = System.Web.HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName]; if (!(basecookie == null)) { filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", "Home" }, { "action", "Sum" } }); } else { filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { { "controller", "User" }, { "action", "Login" } }); } //if (controller == "Home" && action == "Sum") //{ // filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { // { "controller", "User" }, { "action", "Login" } //}); //} //else //{ // filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary { // { "controller", "Home" }, { "action", "Sum" } //}); //} } base.OnActionExecuting(filterContext); }
private democode.mvc.Models.UserModels convertToModel(CustomSecurity.User data) { democode.mvc.Models.UserModels x = new democode.mvc.Models.UserModels(); try { x.UID = data.UID; x.AppID = data.APPID; x.Username = data.UserName; x.IsAnonymous = data.IsAnonymous; x.LastActivityDate = data.LastActivityDate; //x.TimeStamp = data._timestamp; x.Demographics = data.Demographics; x.Membership = data.Membership; x.Role = data.Role; return x; } catch (Exception ex) { return null; } }
/// <summary> /// Add Event Message to system /// </summary> /// <param name="pconstring">as data source connection string</param> /// <param name="level">as event level</param> /// <param name="action">as event action</param> /// <param name="result">as event result</param> /// <param name="message">as event messages in list</param> /// <param name="app">as application</param> /// <param name="appver">as application version</param> /// <param name="opcode">as operation code</param> /// <param name="keys">as key words</param> /// <param name="user">as assoicated user</param> /// <param name="ip">as client's ip address</param> /// <param name="url">as assoicated page url</param> /// <returns></returns> public static bool Add(string pconstring, EventLevel level, EventAction action, EventResult result, String message, String app, String appver = "", String opcode = "", String keys = "", CustomSecurity.User user = null, String ip = "", String url = "") { String suid = ""; if (user != null && user.UID != null) suid = user.UID.ToString(); EventMessage ev = new EventMessage(level: level, action: action, result: result, app: app, message: message, appver: appver, opcode: opcode, keys: keys.ToLower(), uid: suid, ip: ip, url: url); return ev.Add(pconstring); }