public ActionResult Login(MyUser myUser) { UsersDb ubd = new UsersDb(); //построчное чтение и сохранение в лист using (StreamReader sr = new StreamReader(Server.MapPath("~/App_Data/users.txt"))) { string line; while ((line = sr.ReadLine()) != null) { var user = JsonConvert.DeserializeObject <MyUser>(line); ubd.Users.Add(user); } } foreach (var item in ubd.Users) { if (item.Login == myUser.Login && item.Password == myUser.Password) { ViewBag.Logins = ubd.Users; return(View("ShowLogins")); } } ViewBag.Message = "Что-то пошло не так :("; return(View()); }
public OAuthController(UsersDb usersDb, AppsDb appsDb, IPasswordHasher passwordHasher, ITokenService tokenService) { _usersDb = usersDb; _appsDb = appsDb; _passwordHasher = passwordHasher; _tokenService = tokenService; if (!_usersDb.Users.Any()) { _usersDb.Users.Add(new User { Username = "******", Password = _passwordHasher.GenerateIdentityV3Hash("Password") }); _usersDb.Users.Add(new User { Username = "******", Password = _passwordHasher.GenerateIdentityV3Hash("Password") }); _usersDb.SaveChanges(); } if (!_appsDb.Users.Any()) { _appsDb.Users.Add(new AppUser { client_id = "clientid", appSecret = _passwordHasher.GenerateIdentityV3Hash("secret") }); _appsDb.SaveChanges(); } }
/// <summary> /// 验证cookie /// </summary> /// <param name="Username"></param> /// <param name="Passwd"></param> /// <returns>状态</returns> public static bool CookieLoginIn(string Username, string Passwd) { var UserList = CacheHelper.GetCache(Username); if (UserList == null) { UsersDb item = UsersDao.Interface.GetUserInfoByName(Username); if (item != null) { if (item.Passwd == Passwd) { CacheHelper.SetCache(item.Username, item.Passwd); return(true); } } return(false); } else { string Tmp = UserList.ToString(); if (Tmp == Passwd) { return(true); } return(false); } }
public async Task InvokeAsync(HttpContext context, UsersDb db, IClaimsService claimsService) { if (!context.User.Identity.IsAuthenticated || !context.User.TryGetEmail(out var email)) { await _next(context); return; } var identity = context.User.Identities.First(); var user = await db.Users.FirstOrDefaultAsync(x => x.Email == email); if (user == null) { await _next(context); return; } foreach (var claim in await claimsService.GetClaimsAsync(user.Id)) { identity.AddClaim(new Claim(claim.ClaimType, claim.ClaimValue, claim.ClaimValueType, "theapp")); } await _next(context); }
public IActionResult FinishSession([FromBody] UserModel user) { try { //validation of model, this will ensure good data integrity on user data if (user.username != "" && user.username != null) { using (var userDb = new UsersDb()) { //check to ensure the username doesn't exist in the db, if yes, then update the record rather then add if (userDb.Users.SingleOrDefault(c => c.username == user.username) == null) { Startup.DataStorageService.AddUser(user); } else { Startup.DataStorageService.UpdateUser(user); } } //return true, this is used as a flag to ensure data was saved to perform necessary UI actions based on the results return(Json("true")); } } catch { //could add error logging in the future } return(Json("false")); }
public UsersController(IAuthorizationService authorizationService, IClaimsService claimsService, UsersDb db) { _authorizationService = authorizationService; _claimsService = claimsService; _db = db; }
public void UsersDbAddUserReturnsTrue() { //Assign var usersDb = new UsersDb(); //Act + Assert Assert.IsTrue(usersDb.AddUser("", "")); }
public void UsersDbGetAuthorizedUsersReturnsListAuthorizedUsers() { //Assign var usersDb = new UsersDb(); //Act + Assert Assert.IsTrue(usersDb.GetAuthorizedUsers() is List <AuthorizedUser>); }
public ManageUsers() { InitializeComponent(); _database = new UsersDb(); var users = _database.GetUsers(); lstData.ItemsSource = users; }
public async void AddUser(UserModel user) { //save user object to db using (var usersDb = new UsersDb()) { usersDb.Users.Add(user); await usersDb.SaveChangesAsync(); } }
public void UsersDbGetUserReturnsIUser() { //Assign var usersDb = new UsersDb(); usersDb.AddUser("", ""); //Act + Assert Assert.IsTrue(usersDb.GetUser("", "") is IUser); }
private async void completeForm() { var model = new Book { Photo = "https://d1w7fb2mkkr3kw.cloudfront.net/assets/images/book/lrg/9781/1188/9781118881170.jpg", Edition = editionInput.Text, Title = titleInput.Text, Author = authorInput.Text, Posted = DateTime.Now, Faculty = facultySelection.SelectedItem.ToString(), CourseCode = courseCodeInput.Text, Price = float.Parse(priceInput.Text), Condition = conditionSelection.SelectedItem.ToString(), Description = descInput.Text.Trim(), Campus = campusSelection.SelectedItem.ToString() }; model.BooksImgs = JsonConvert.SerializeObject(imagePaths); //---------------------------------------------------------------------------// #region //Book book = new Book(); //book.Title = titleInput.Text.Trim(); //titleInput.Text = null; //book.Author = authorInput.Text.Trim(); //authorInput.Text = null; //book.Edition = editionInput.Text.Trim(); //editionInput.Text = null; //book.CourseCode = courseCodeInput.Text.Trim(); //courseCodeInput.Text = null; //book.Faculty = facultySelection.SelectedItem.ToString(); //facultySelection.SelectedIndex = 0; //book.Condition = conditionSelection.SelectedItem.ToString(); //conditionSelection.SelectedIndex = 0; //book.Description = descInput.Text.Trim(); //descInput.Text = null; //book.Price = float.Parse(priceInput.Text.Trim()); //priceInput.Text = null; //book.Campus = "City"; #endregion UsersDb.AddUser(new User()); BooksDb.AddBook(model); await DisplayAlert("Complate", "Your Book will post on the list soon", "OK"); Application.Current.MainPage = new HomePage(); await Shell.Current.GoToAsync("//main"); }
public void OnSaveClicked(object sender, EventArgs args) { usersDb = new UsersDb(); user.Username = txtUserName.Text; user.Email = txtEmail.Text; user.Password = txtPassword.Text; user.ConfirmPassword = txtConfirmPassword.Text; usersDb.EditUser(user); Navigation.PushAsync(new ManageUsers()); }
/// <summary> /// If disposing, calls dispose on the usersDb. Always nulls out the usersDb /// </summary> /// <param name="disposing"></param> protected virtual void Dispose(bool disposing) { if (DisposeUserDb && disposing && UsersDb != null) { UsersDb.Dispose(); } _disposed = true; UsersDb = null; }
public async Task UpdateAsync(IdentityUser user) { ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException("user"); } await Task.Run(() => UsersDb.Update(user)); }
public void UpdateTourVisit(int userId) { var db = ObjectContextFactory.Create(); UsersDb user = db.Users.Where(w => w.UserID == userId).FirstOrDefault(); if (user != null) { user.HasTourCompleted = true; db.SaveChanges(); } }
public async void OnDeleteClicked(object sender, EventArgs args) { usersDb = new UsersDb(); bool accepted = await DisplayAlert("Confirm", "Are you Sure ?", "Yes", "No"); if (accepted) { usersDb.DeleteUser(user); } await Navigation.PushAsync(new ManageUsers()); }
public IActionResult Get(int id) { UsersDb userFind = _userContext.Users.FirstOrDefault(u => u.UsersId == id); if (userFind == null) { return(NotFound("Not found")); } DTO.Request.Users user = new DTO.Request.Users(userFind.UsersId, userFind.Name, userFind.Email, userFind.RegisteredNumber); return(Ok(user)); }
public Task SetEmailAsync(IdentityUser user, string email) { ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException("user"); } user.Email = email; UsersDb.Update(user); return(Task.FromResult(0)); }
public async void UpdateUser(UserModel user) { //Find old user data, and update it with the incoming data model, then save changes to db using (var usersDb = new UsersDb()) { var oldDbUserData = await usersDb.Users.FirstOrDefaultAsync(c => c.username == user.username); oldDbUserData.correctAnswers += user.correctAnswers; oldDbUserData.incorrectAnswers += user.incorrectAnswers; await usersDb.SaveChangesAsync(); } }
protected void Page_Load(object sender, EventArgs e) { if (Session["LoggedIn"] != null) { UsersDb usersDb = new UsersDb(); Users user = usersDb.GetUserById(Convert.ToInt32(Session["LoggedIn"])); currentUser = user; } else { Response.Redirect("~/Login.aspx"); } }
public IActionResult Put(int id, DTO.Create.Users newUser) { if (newUser == null) { return(NotFound("Not found")); } UsersDb user = new UsersDb(newUser); user.UsersId = id; _userContext.Users.Update(user); _userContext.SaveChanges(); return(Ok(newUser)); }
public Task SetPasswordHashAsync(IdentityUser user, string passwordHash) { ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException("user"); } var account = UsersDb.IdentityAccounts.First(w => w.UserId == user.Id); account.Password = passwordHash; UsersDb.Update(account); return(Task.FromResult(0)); }
public Task SetEmailConfirmedAsync(IdentityUser user, bool confirmed) { ThrowIfDisposed(); if (user == null) { throw new ArgumentNullException("user"); } var account = UsersDb.IdentityAccounts.First(w => w.UserId == user.Id); account.IsApproved = confirmed; UsersDb.Update(account); return(Task.FromResult(0)); }
private bool DoesUserExist(string email) { UsersDb _usersDb = new UsersDb(); Users user = _usersDb.GetUserByEmail(email); if (user.Id == 0) { return(false); } else { return(true); } }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, UsersDb usersDb) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); usersDb.Database.Migrate(); } app.UseAuthentication(); app.UseStaticFiles(); app.UseMvcWithDefaultRoute(); }
public IActionResult Post(DTO.Create.Users newUser) { if (newUser == null) { return(NotFound("Empty user")); } UsersDb user = new UsersDb(newUser); _userContext.Users.Add(user); _userContext.SaveChanges(); UsersDb userDB = _userContext.Users.OrderByDescending(u => u.UsersId).FirstOrDefault(); DTO.Request.Users userFind = new DTO.Request.Users(userDB.UsersId, userDB.Name, userDB.Email, userDB.RegisteredNumber); return(Ok(userFind)); }
public async Task <IActionResult> Post(Exam exam) { if (exam == null) { return(NotFound("Empty exam")); } UsersDb users = _examContext.Users.FirstOrDefault(u => u.UsersId == exam.UsersId); PatientDb patient = _examContext.Patient.FirstOrDefault(p => p.PatientId == exam.PatientId); ExamDb newExam = new ExamDb(exam, patient, users); await _examContext.Exam.AddAsync(newExam); await _examContext.SaveChangesAsync(); return(Ok(_examContext.Exam.ToList())); }
public IActionResult Put(int id, Exam newExam) { if (newExam == null) { return(NotFound("Not found")); } UsersDb users = _examContext.Users.FirstOrDefault(u => u.UsersId == newExam.UsersId); PatientDb patient = _examContext.Patient.FirstOrDefault(p => p.PatientId == newExam.PatientId); ExamDb exam = new ExamDb(newExam, patient, users); exam.ExamId = id; _examContext.Exam.Update(exam); _examContext.SaveChanges(); return(Ok(newExam)); }
async void OnAuthCompleted(object sender, AuthenticatorCompletedEventArgs e) { var authenticator = sender as OAuth2Authenticator; if (authenticator != null) { authenticator.Completed -= OnAuthCompleted; authenticator.Error -= OnAuthError; } User user = null; if (e.IsAuthenticated) { //UserInfo = https://www.googleapis,com/oaurh2/v2/userinfo var request = new OAuth2Request("GET", new Uri(Constants.UserInfoUrl), null, e.Account); var response = await request.GetResponseAsync(); if (response != null) { string userJson = await response.GetResponseTextAsync(); user = JsonConvert.DeserializeObject <User>(userJson); } if (account != null) { store.Delete(account, Constants.AppName); } await store.SaveAsync(account = e.Account, Constants.AppName); await DisplayAlert("Name", User.Name, "OK"); await DisplayAlert("Email Address", User.Email, "OK"); try { UsersDb.AddUser(user); } catch (SqlException ex) { } App.CurrentUser = user; } Application.Current.MainPage = new HomePage(); await Shell.Current.GoToAsync("//main"); }