private ChatUser GetChatUserFromUser([NotNull] User user) { if (user == null) { throw new ArgumentNullException("user"); } var myRoomId = this.GetMyRoomId(); ChatUser.StatusType userStatus; lock (connections) { userStatus = connections.ContainsKey(myRoomId) ? (connections[myRoomId].ContainsKey(user.Id) ? ChatUser.StatusType.Online : ChatUser.StatusType.Offline) : ChatUser.StatusType.Offline; } return(new ChatUser() { Id = user.Id, Name = user.Person.FullName, Status = userStatus, ProfilePictureUrl = GravatarHelper.GetGravatarUrl(user.Person.EmailGravatarHash, GravatarHelper.Size.s32) }); }
/// <summary> /// Creates a new user and adds it to the storage object context. /// </summary> /// <param name="userToUpdate">User object to update the data.</param> /// <param name="registrationData">Object containing informations about the user to be created.</param> /// <param name="dbUserSet">Storage object context used to add the new user. It won't be saved, just changed.</param> /// <param name="utcNow"> </param> /// <returns>An enumerated value indicating what has happened.</returns> public static CreateUserResult UpdateUser(User userToUpdate, CreateAccountViewModel registrationData, IObjectSet <User> dbUserSet, DateTime utcNow) { // Password cannot be null, nor empty. if (string.IsNullOrEmpty(registrationData.Password)) { return(CreateUserResult.InvalidUserNameOrPassword); } // User-name cannot be null, nor empty. if (string.IsNullOrEmpty(registrationData.UserName)) { return(CreateUserResult.InvalidUserNameOrPassword); } // Password salt and hash. string passwordSalt = CipherHelper.GenerateSalt(); var passwordHash = CipherHelper.Hash(registrationData.Password, passwordSalt); // Normalizing user name. // The normalized user-name will be used to discover if another user with the same user-name already exists. // This is a security measure. This makes it very difficult to guess what a person's user name may be. // You can only login with the exact user name that you provided the first timestamp, // but if someone tries to register a similar user name just to know if that one is the one you used... // the attacker won't be sure... because it could be any other variation. // e.g. I register user-name "Miguel.Angelo"... the attacker tries to register "miguelangelo", he'll be denied... // but that doesn't mean the exact user-name "miguelangelo" is the one I used, in fact it is not. var normalizedUserName = StringHelper.NormalizeUserName(registrationData.UserName); var isUserNameAlreadyInUse = dbUserSet.Any(u => u.UserNameNormalized == normalizedUserName && u.PracticeId == userToUpdate.PracticeId && u.Id != userToUpdate.Id); if (isUserNameAlreadyInUse) { return(CreateUserResult.UserNameAlreadyInUse); } // Note: DateOfBirth property cannot be set in this method because of Utc/Local conversions. // The caller of this method must set the property. userToUpdate.Person.Gender = registrationData.Gender ?? 0; userToUpdate.Person.FullName = registrationData.FullName; userToUpdate.Person.CreatedOn = utcNow; userToUpdate.Person.Email = registrationData.EMail; userToUpdate.Person.EmailGravatarHash = GravatarHelper.GetGravatarHash(registrationData.EMail); userToUpdate.UserName = registrationData.UserName; userToUpdate.UserNameNormalized = normalizedUserName; userToUpdate.PasswordSalt = passwordSalt; userToUpdate.Password = passwordHash; userToUpdate.SYS_PasswordAlt = null; userToUpdate.LastActiveOn = utcNow; return(CreateUserResult.Ok); }
public void InitDoctor() { if (this.wasInitDoctorCalled) { return; } this.wasInitDoctorCalled = true; // the URL's doctor identifier (doctor's name) var doctorIdentifier = this.RouteData.Values["doctor"] as string; // Getting list of all doctors in this practice. var allDoctors = this.db.Doctors .Include("Users") .Include("Users.Person") .ToList(); // Resolved: uniqueness of UrlIdentifier is ensured. // issue: 2 doctors with the same name would cause this query to fail // the doctor being visualized (not the user as a doctor) var doctor = allDoctors .FirstOrDefault(d => d.UrlIdentifier == doctorIdentifier); Debug.Assert(doctor != null, "doctor must not be null"); //if (doctor == null) // return; this.Doctor = doctor; var doctorViewModels = allDoctors.Select(doc => new DoctorViewModel { Id = doc.Id, Name = doc.Users.ElementAt(0).Person.FullName, UrlIdentifier = doc.UrlIdentifier, ImageUrl = GravatarHelper.GetGravatarUrl(doc.Users.ElementAt(0).Person.EmailGravatarHash, GravatarHelper.Size.s32), CRM = doc.CRM, MedicalSpecialty = doc.MedicalSpecialtyName, IsScheduleConfigured = doc.CFG_Schedule != null, MedicalEntity = string.Format( string.IsNullOrEmpty(doc.MedicalEntityJurisdiction) ? "{0}" : "{0}-{1}", doc.MedicalEntityCode, doc.MedicalEntityJurisdiction), }) .ToList(); this.ViewBag.Doctor = doctorViewModels.FirstOrDefault(doc => doc.Id == doctor.Id); this.ViewBag.AllDoctors = doctorViewModels; }