Beispiel #1
0
        public GamePage(CGameStartModel model)
        {
            InitializeComponent();
            IDataBaseAccessService client = SDbService.Get();

            switch (model.MySideColor)
            {
            case EPieceColor.White:
                WhitePlayerBadge.Content = new PlayerBadgeControl(
                    CAuthenticationStaff.Instance.User.Nickname,
                    client.GetWinRate(CAuthenticationStaff.Instance.User.UserId));
                BlackPlayerBadge.Content = new PlayerBadgeControl(
                    client.FindUserById(model.OpponentId).Nickname,
                    client.GetWinRate(model.OpponentId));
                break;

            case EPieceColor.Black:
                WhitePlayerBadge.Content = new PlayerBadgeControl(
                    client.FindUserById(model.OpponentId).Nickname,
                    client.GetWinRate(model.OpponentId));
                BlackPlayerBadge.Content = new PlayerBadgeControl(
                    CAuthenticationStaff.Instance.User.Nickname,
                    client.GetWinRate(CAuthenticationStaff.Instance.User.UserId));
                break;

            default:
                throw new InvalidEnumArgumentException("Unknown or undefined player side color");
            }
            DataContext = new CGamePageViewModel(model.GameId, model.MySideColor);
        }
Beispiel #2
0
        public Boolean TrySignUp(String nickname, String password)
        {
            IDataBaseAccessService client = SDbService.Get();

            if (client.FindUserByNickname(nickname) != null)
            {
                return(false);
            }
            Guid   userId = Guid.NewGuid();
            String salt   = CSaltGenerator.Instance.GetNewSalt();
            CUser  user   = new CUser
            {
                Nickname         = nickname,
                UserId           = userId,
                RegistrationDate = DateTime.UtcNow,
                Authentication   = new CAuthentication()
                {
                    UserId       = userId,
                    Salt         = salt,
                    PasswordHash = ComputePasswordHash(password, salt)
                }
            };

            return(client.AddUser(user));
        }
Beispiel #3
0
 public BasicAuthHandler(
     IOptionsMonitor <AuthenticationSchemeOptions> options,
     ILoggerFactory logger,
     UrlEncoder encoder,
     ISystemClock clock,
     SDbService service
     ) : base(options, logger, encoder, clock)
 {
 }
Beispiel #4
0
 public async Task InvokeAsync(HttpContext httpContext, SDbService service)
 {
     httpContext.Request.EnableBuffering();
     if (httpContext.Request != null)
     {
         string method      = httpContext.Request.Method;
         string path        = httpContext.Request.Path;
         string bodyStr     = "";
         string queryString = httpContext.Request.QueryString.ToString();
         using (StreamReader reader = new StreamReader(httpContext.Request.Body, Encoding.UTF8, true, 1024, true))
         {
             bodyStr = await reader.ReadToEndAsync();
         }
         service.SaveLogData(method, queryString, path, bodyStr);
     }
     httpContext.Request.Body.Seek(0, SeekOrigin.Begin);
     await _next(httpContext);
 }
Beispiel #5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, SDbService service)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            //	app.UseSwagger();

            //app.UseSwaggerUI(c =>
            //{
            //		c.SwaggerEndpoint("/swagger/v1/swagger.json", "Student API V1");
            //		});

            //		app.UseMiddleware<LoggingMiddleware>();

            //	app.Use(async (context, next) =>
            //	{
            //		if (!context.Request.Headers.ContainsKey("Index"))
            //		{
            //			context.Response.StatusCode = StatusCodes.Status401Unauthorized;
            //			await context.Response.WriteAsync("Index number required");
            //			return;
            //		}
            //		string index = context.Request.Headers["Index"].ToString();
            //		var st = service.GetStudentByIndex(index);
            //		if (st == null)
            //		{
            //			context.Response.StatusCode = StatusCodes.Status400BadRequest;
            //			await context.Response.WriteAsync("Incorrect Index Number");
            //		return;
            //		}
            //		await next();
            //	});
            //app.UseHttpsRedirection();

            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });
        }
Beispiel #6
0
        public CUser TryLogIn(String nickname, String password)
        {
            IDataBaseAccessService client = SDbService.Get();
            CUser user = client.FindRegisteredUser(nickname);

            if (user == null)
            {
                return(null);
            }
            if (_onlineUsers.Contains(user.UserId))
            {
                return(null);
            }
            if (!ComputePasswordHash(password, user.Authentication.Salt).SequenceEqual(user.Authentication.PasswordHash))
            {
                return(null);
            }
            _onlineUsers.Add(user.UserId);
            user.Authentication = null;
            return(user);
        }
Beispiel #7
0
 public EnrollmentsController(SDbService db)
 {
     _db = db;
 }
Beispiel #8
0
 public StudentController(SDbService db, IConfiguration configuration)
 {
     _db = db; Configuration = configuration;
 }