public void GetSubscriptionExpiredDate_Ok(User.UserRole role) { var user = User.Create(VALID_NAME, VALID_LASTNAME, VALID_CREDENTIALS, VALID_PROFILEPHOTO, role); var dtoService = new DateTimeOffsetServiceMock(DateTimeOffset.Now); if (role == User.UserRole.Registered) { user.ChangeRegistrationToConfirmed(dtoService); } var expireDate = user.GetSubscriptionExpiredDate(); switch (role) { case User.UserRole.Registered: Assert.IsTrue(expireDate == dtoService.Now + TimeSpan.FromDays(365)); break; case User.UserRole.Admin: Assert.IsNull(expireDate); break; default: throw new InvalidOperationException("missing role"); } }
public User CreateUser( String username, User.UserRole role = User.UserRole.Readable ) { return(new User(username, role)); }
public void ChangeRegistrationToConfirmed_VerifyUserAllowed(User.UserRole confirmedUserRole, bool confirmTwice, bool canConfirm) { var confirmedUser = User.Create(VALID_NAME, VALID_LASTNAME, VALID_CREDENTIALS, VALID_PROFILEPHOTO, confirmedUserRole); var now = DateTimeOffset.Now; var dateTimeOffsetService = new DateTimeOffsetServiceMock(now); var isConfirmed = true; try { confirmedUser.ChangeRegistrationToConfirmed(dateTimeOffsetService); if (confirmTwice) { confirmedUser.ChangeRegistrationToConfirmed(dateTimeOffsetService); } } catch (UserException exc) when(exc.Code == (int)UserException.UserExceptionCode.CannotConfirmRegistration) { isConfirmed = false; } Assert.AreEqual(canConfirm, isConfirmed); if (canConfirm) { Assert.AreEqual(now, confirmedUser.SubscriptionDate); } }
IDictionary <string, object> CreateUpdateParams(dlgTeacher dlg, int id) { var sqlParamWithValue = new Dictionary <string, object>(); User.UserRole R = (User.UserRole)Enum.Parse(typeof(User.UserRole), dlg.cbRole.SelectedValue.ToString()); sqlParamWithValue.Add("@ID", id); sqlParamWithValue.Add("@Rola", R); sqlParamWithValue.Add("@Status", dlg.chkStatus.Checked); sqlParamWithValue.Add("@User", UserSession.User.Login); sqlParamWithValue.Add("@IP", AppSession.HostIP); return(sqlParamWithValue); }
public static User GenerateUser(User.UserRole role = User.UserRole.Registered) { var user = User.Create(VALID_NAME, VALID_LASTNAME, Credentials.Create(DataGenerator.GenerateMail() + generator_counter, VALID_PASSWORD), VALID_PROFILEPHOTO, role); generator_counter++; return(user); }
public void UpdateUserRole(int userId, User.UserRole userRole) { using (var connection = GetConnection()) { var command = connection.CreateCommand(); command.CommandType = CommandType.Text; command.CommandText = "UPDATE users set role = @role where id = @userId"; command.Parameters.Add(new MySqlParameter("@userId", userId)); command.Parameters.Add(new MySqlParameter("@role", userRole.ToString())); command.ExecuteNonQuery(); } }
public void CreateUser(string email, string password, string nickname, User.UserRole role) { using (var connection = GetConnection()) { var command = connection.CreateCommand(); command.CommandType = CommandType.Text; command.CommandText = "INSERT INTO users (nickname, email, password, role, banned) VALUES(@nickname, @email, @password, @role, @banned)"; command.Parameters.Add(new MySqlParameter("@email", email)); command.Parameters.Add(new MySqlParameter("@nickname", nickname)); command.Parameters.Add(new MySqlParameter("@password", password)); command.Parameters.Add(new MySqlParameter("@banned", "false")); command.Parameters.Add(new MySqlParameter("@role", role.ToString())); command.ExecuteNonQuery(); } }
IDictionary <string, object> CreateInsertParams() { var sqlParamWithValue = new Dictionary <string, object>(); var SaltedPasswordHash = Enigma.HashHelper.CreatePassword(txtPassword.Text.Trim()); User.UserRole R = (User.UserRole)Enum.Parse(typeof(User.UserRole), cbRola.SelectedValue.ToString()); sqlParamWithValue.Add("@Login", txtLogin.Text.Trim()); sqlParamWithValue.Add("@LastName", txtNazwisko.Text.Trim()); sqlParamWithValue.Add("@FirstName", txtImie.Text.Trim()); sqlParamWithValue.Add("@Password", Convert.ToBase64String(SaltedPasswordHash)); sqlParamWithValue.Add("@Role", R); sqlParamWithValue.Add("@Status", chkStatus.Checked); sqlParamWithValue.Add("@Sex", chkSex.Checked); sqlParamWithValue.Add("@Faximile", pbFaximile.Image); sqlParamWithValue.Add("@Email", txtEmail.Text.Trim()); sqlParamWithValue.Add("@Owner", UserSession.User.Login); sqlParamWithValue.Add("@User", UserSession.User.Login); sqlParamWithValue.Add("@IP", AppSession.HostIP); return(sqlParamWithValue); }
protected override object GetFormattedValue(object value, int rowIndex, ref DataGridViewCellStyle cellStyle, TypeConverter valueTypeConverter, TypeConverter formattedValueTypeConverter, DataGridViewDataErrorContexts context) { User.UserRole role = (User.UserRole)(int) value; switch (role) { case User.UserRole.Admin: return("Сотрудник деканата"); case User.UserRole.Professor: return("Преподаватель"); case User.UserRole.Student: return("Студент"); default: throw new NotImplementedException(); } ; }
private async Task <int> UpdateUserAsync(dlgUser dlg, string login) { User.UserRole R = User.UserRole.Rodzic; // = (User.UserRole)Enum.Parse(typeof(User.UserRole), dlg.cbRola.SelectedValue.ToString()); Enum.TryParse(dlg.cbRola.SelectedValue.ToString(), out R); var sqlParamWithValue = new Dictionary <string, object>() { { "@Login", login }, { "@Nazwisko", dlg.txtNazwisko.Text.Trim() }, { "@Imie", dlg.txtImie.Text.Trim() }, { "@Rola", R }, { "@Email", dlg.txtEmail.Text.Trim() }, { "@Status", dlg.chkStatus.Checked }, { "@Sex", dlg.chkSex.Checked }, { "@User", UserSession.User.Login }, { "@IP", AppSession.HostIP } }; using (var scope = AppSession.TypeContainer.BeginLifetimeScope()) { var dbs = scope.Resolve <IDataBaseService>(); return(await dbs.UpdateRecordAsync(UserSQL.UpdateUser(), sqlParamWithValue)); } }
/// TODO: MOVE public static async Task <bool> CreateUser(DbCtx ctx, string primaryKey, User.UserRole role) { try { User user = new User() { Role = role.ToString() }; await ctx.Users.AddAsync(user); if (role == User.UserRole.patient) { Patient patient = new Patient() { User = user, Id = primaryKey }; await ctx.Patients.AddAsync(patient); } else { Carer carer = new Carer() { User = user, Email = primaryKey }; await ctx.Carers.AddAsync(carer); } await ctx.SaveChangesAsync(); return(true); } catch (Exception e) { Console.WriteLine(e); } return(false); }
protected async Task <LoggedInUserDto> LoginAsync_CredentialsTest(DbContextOptionsBuilder <ModelContext> builder, Credentials credentials, User.UserRole role, bool isConfirmed = true) { var ctx = this.GetModelContext(builder); var dbAccess = GetDbAccessInstance(ctx); var user = User.Create(UserUtils.VALID_NAME, UserUtils.VALID_LASTNAME, UserUtils.VALID_CREDENTIALS, UserUtils.VALID_PROFILEPHOTO, role); if (isConfirmed) { user.ChangeRegistrationToConfirmed(new DateTimeOffsetService()); } try { await ctx.Users.AddAsync(user); await ctx.SaveChangesAsync(); var loggedUser = await dbAccess.LoginAsync(credentials); return(loggedUser); } finally { ctx.Users.Remove(user); await ctx.SaveChangesAsync(); } }
/// <summary> /// Changes a users rank, purges the cache, and notifies other logged in users /// </summary> /// <param name="user">The user to change the rank of</param> /// <param name="newRank">The rank that you wish to change the user to</param> public static void ChangeRank(User user, User.UserRole newRank) { user.Role = newRank; user.UpdateRole(); Purge(user); }