Beispiel #1
0
        /// <summary>
        /// constructor that creates a user object identified by the data from the user with the given email-password-combination
        /// </summary>
        /// <param name="email">email address the user uses to login</param>
        /// <param name="password">users password to login</param>
        /// <returns>the user object if password/email match, otherwise null</returns>
        public UserModel(string email, string password)
        {
            var service = new UtilityService();
            string hashedPassword = service.GetMd5Hash(password);
            ml_User user = null;
            using (MuscleLogContext context = new MuscleLogContext())
            {
                user = context.ml_User.Where(u => u.userEmail == email && u.userPassword == hashedPassword).FirstOrDefault();
            }

            if(user != null) {
                // set values if user/password combination is correct
                userEmail = user.userEmail;
                userName = user.userName;
                userStatus = (Util.Enum.UserStatus)(user.userStatus ?? 100);
                _userID = user.ID;
            } else {
                // otherwise set UserID to -1 and indicate a non-existant user
                _userID = -1;
            }
        }
 /// <summary>
 /// laedt ein UserModel-Object anhand der Login Daten
 /// </summary>
 /// <param name="email">Login-Email</param>
 /// <param name="password">Login-Passwort</param>
 /// <returns>Gibt das UserModel bei erfolgreichen Login zurueck, andernfalls NULL</returns>
 public ml_User Load(string email, string password)
 {
     var service = new UtilityService();
     string hashedPwd = service.GetMd5Hash( password );
     var userObject = _repo.GetAll(u => u.userEmail == email && u.userPassword == hashedPwd).FirstOrDefault();
     if (userObject == null)
     {
         throw new muscle_log.framework.Exceptions.InvalidCredentialsException("The e-mail-address or the password are incorrect.");
     }
     return userObject;
 }
        public ActionResult SaveUserInfo(UserInfoSettings model, FormCollection formData)
        {
            var utilityService = new UtilityService();

            // Formular-Daten validieren
            if (ModelState.IsValid)
            {
                bool errors = false;

                // custom validation
                if (model.Password != null && !model.Password.Equals(model.PasswordConfirm) && !String.IsNullOrEmpty(model.Password.Trim()))
                {
                    ModelState.AddModelError("passwordsUnequal", "Die Passwörter stimmen nicht überein.");
                    errors = true;
                }

                if (!utilityService.ValidateDatetime(model.Birthday) && model.Birthday != null)
                {
                    ModelState.AddModelError("birthdayInvalid", "Der angegebene Geburtstag ist kein gültiges Datum.");
                    errors = true;
                }

                if (!errors)
                {

                    // Daten fuer CurrentUser speichern
                    CurrentUser.birthday = DateTime.Parse(model.Birthday);
                    CurrentUser.firstName = model.FirstName;
                    CurrentUser.lastName = model.LastName;
                    CurrentUser.userName = model.UserName;

                    if (model.Password != null && !String.IsNullOrEmpty(model.Password.Trim()))
                    {
                        CurrentUser.userPassword = utilityService.GetMd5Hash(model.Password);
                    }
                    _service.Save(CurrentUser);
                    _unitOfWork.SaveChanges();
                }
            }

            return View("Settings");
        }