public async Task Setup() { _storageStudent = new Student { FirstName = "name 1", LastName = "surname 1", Email = "*****@*****.**", UserName = "******", GitLink = "gitLink 1", GroupId = 1, Id = "studentId 1" }; var options = new DbContextOptionsBuilder <UsersStorage>() .UseInMemoryDatabase("project_reporter") .Options; _storage = new UsersStorage(options); _storage.Students.RemoveRange(_storage.Students.ToList()); await _storage.SaveChangesAsync(); await _storage.Students.AddAsync(_storageStudent); await _storage.SaveChangesAsync(); }
public DataGenerator(GroupsStorage groupsStorage, UsersStorage usersStorage) { _groupsStorage = groupsStorage; _usersStorage = usersStorage; _rand = new Random(); }
public async Task Setup() { _storageTeacher = new Teacher { FirstName = "name 1", LastName = "surname 1", Email = "*****@*****.**", UserName = "******", Department = new Department { FacultyId = 1, Id = 1, Name = "department 1" }, Id = "teacherId 1" }; var options = new DbContextOptionsBuilder <UsersStorage>() .UseInMemoryDatabase("project_reporter") .Options; _storage = new UsersStorage(options); _storage.Teachers.RemoveRange(_storage.Teachers.ToList()); _storage.Departments.RemoveRange(_storage.Departments.ToList()); await _storage.SaveChangesAsync(); await _storage.Teachers.AddAsync(_storageTeacher); await _storage.SaveChangesAsync(); }
private void ProcessNewUsers(IEnumerable <User> users) { if (users == null) { return; } var usersArray = users as User[] ?? users.ToArray(); if (!usersArray.Any()) { return; } _lastUserId = usersArray.Last().Id; lock (UsersStorage) { foreach (var user in usersArray) { if (!UsersStorage.ContainsKey(user.Id)) { UsersStorage.Add(user.Id, user); } } } NewUsersEvent?.Invoke(this, usersArray); }
public Task AuthenticateAsync(HttpAuthenticationContext context, CancellationToken cancellationToken) { context.Principal = null; IEnumerable <string> headers; if (context.Request.Headers.TryGetValues("accessToken", out headers) == true) { var accessToken = headers.First(); var user = UsersStorage.Find(accessToken, DateTime.Now); if (user != null) { var getnericIdentiry = new GenericIdentity(user.Login); getnericIdentiry.AddClaim(new Claim("Id", user.Id + "")); getnericIdentiry.AddClaim(new Claim("Login", user.Login)); getnericIdentiry.AddClaim(new Claim("Password", user.Password)); getnericIdentiry.AddClaim(new Claim("AccessToken", accessToken)); context.Principal = new GenericPrincipal(getnericIdentiry, null); } else { context.ErrorResult = new AuthenticationErrorResult("Не действительный токен доступа."); } } else { context.ErrorResult = new AuthenticationErrorResult("Не указан токен доступа."); } return(Task.FromResult <object>(null)); }
private void GenerateUsers() { UsersStorage.Add(new User { ID = 1, Login = "******", Password = "******" }); UsersStorage.Add(new User { ID = 1, Login = "******", Password = "******" }); UsersStorage.Add(new User { ID = 1, Login = "******", Password = "******" }); }
public Result <object> Exit(string login) { try { UsersStorage.Remove(login); return(new Result <object>()); } catch (Exception e) { return(new Result <object>(e.Message)); } }
public void SetUserInfo(int userId, UserInfo userInfo) { lock (UsersStorage) { if (!UsersStorage.ContainsKey(userId)) { throw new ArgumentException("No such user exists"); } var user = UsersStorage[userId].CloneJson(); user.UserInfo = userInfo; UsersStorage[userId] = user; if (_newUserInfoHandlers.ContainsKey(userId)) { _newUserInfoHandlers[userId]?.Invoke(this, UsersStorage[userId]); } } }
static Dependencies() { UsersStorage usersStorage = new UsersStorage(); AwardsStorage awardsStorage = new AwardsStorage(); UsersAwardsStorage usersAwardsStorage = new UsersAwardsStorage(); UsersStorage = usersStorage; AwardsStorage = awardsStorage; UsersAwardsStorage = usersAwardsStorage; UsersSaver = usersStorage; AwardsSaver = awardsStorage; UsersAwardsSaver = usersAwardsStorage; UsersManager = new UsersManager(UsersStorage, UsersSaver); AwardsManager = new AwardsManager(AwardsStorage, AwardsSaver); UsersAwardsManager = new UsersAwardsManager(UsersAwardsStorage, UsersAwardsSaver, UsersManager, AwardsManager); }
public void SetUser(User user) { lock (UsersStorage) { if (UsersStorage.ContainsKey(user.Id)) { UsersStorage[user.Id] = user; if (_newUserInfoHandlers.ContainsKey(user.Id)) { _newUserInfoHandlers[user.Id]?.Invoke(this, user); } } else { UsersStorage.Add(user.Id, user); NewUsersEvent?.Invoke(this, new[] { user }); } } }
public Result <ViewModel.Doctor> Enter(string login, string password) { try { var doctorDataBase = new DoctorDataBase(ConnectionStringPattern, Login, Password); var doctor = doctorDataBase.GetUser(login); var accessToken = Guid.NewGuid().ToString(); var user = new User() { Id = doctor.Id, AccessToken = accessToken, DateTime = DateTime.Now, Login = login, Password = password }; UsersStorage.Add(user); return(new Result <ViewModel.Doctor>(new ViewModel.Doctor() { access_token = accessToken, fio = doctor.Fio })); } catch (Exception e) { return(new Result <ViewModel.Doctor>(e.Message)); } }
private HttpRequest Create(IOwinRequest owinRequest) { var request = new HttpRequest() { DateTime = DateTime.Now, Host = owinRequest.Host.Value, Method = owinRequest.Method, Url = owinRequest.Path.Value, QueryString = owinRequest.QueryString.Value }; string[] headers; if (owinRequest.Headers.TryGetValue("accessToken", out headers) == true) { var accessToken = headers.First(); var user = UsersStorage.Find(accessToken, DateTime.Now); if (user != null) { request.Login = user.Login; } } using (var reader = new StreamReader(owinRequest.Body, Encoding.UTF8)) { request.Body = reader.ReadToEnd(); } var memoryStream = new MemoryStream(); var bytesToWrite = Encoding.UTF8.GetBytes(request.Body); memoryStream.Write(bytesToWrite, 0, bytesToWrite.Length); memoryStream.Seek(0, SeekOrigin.Begin); owinRequest.Body = memoryStream; return(request); }
public UsersRepository(UsersStorage storage, IStorageUserReconstructionFactory reconstructionFactory) { _storage = storage; _reconstructionFactory = reconstructionFactory; }
public UsersController(IConfiguration config) { _storage = new UsersStorage(config); }
public void AddUser(User user) { UsersStorage.AddUser(user); }
public IEnumerable <User> GetAllUsers() { return(UsersStorage.SelectAllUsers()); }
public void DeleteUser(int userId) { UsersStorage.DeleteUserById(userId); }
public DatabaseUploader(UsersStorage storage) { _storage = storage; }
public UsersController() { _storage = new UsersStorage(); }