public static bool SendForgotPasswordEmail(UserModel user, string passwordResetUrl)
        {
            bool result = true;
            try
            {
                var email = new MailMessage();

                //email.From = new MailAddress("*****@*****.**");
                email.To.Add(new MailAddress(user.Email));

                email.Subject =  Resources.Email_PasswordReset_Title;
                email.IsBodyHtml = true;

                email.Body = Resources.Email_PasswordReset_Body +
                           "<a href='" + passwordResetUrl + "'>" + passwordResetUrl + "</a>";

                SmtpClient smtpClient = new SmtpClient();

                smtpClient.Send(email);
            }
            catch (Exception ex)
            {
                Trace.TraceError("Caught exception sending password reset email " + ex);
                result = false;
            }
            return result;
        }
 public UserModel CreateUser(string username, string password, string givenName, string surname, string email, Guid id)
 {
     var user = new UserModel
     {
         Username = username.ToLowerInvariant(),
         GivenName = givenName,
         Surname = surname,
         Email = email,
         Id = id
     };
     ADBackend.Instance.Users.Add(user);
     return user;
 }
        public void EnsureCollectionsAreValid()
        {
            if (Administrators == null)
            {
                Administrators = new UserModel[0];
            }

            if (Users == null)
            {
                Users = new UserModel[0];
            }

            if (Teams == null)
            {
                Teams = new TeamModel[0];
            }
        }
 private void AddUserToRepo(Guid repoId, UserModel user)
 {
     UpdateRepo(repoId, repo => repo.Users = new[] { user });
 }
 private void AddAdminToRepo(Guid repoId, UserModel adminUser)
 {
     UpdateRepo(repoId, repo => repo.Administrators = new[] { adminUser });
 }
        private UserModel GetUserModelFromPrincipal(UserPrincipal user)
        {
            UserModel result = null;

            try
            {
                if (user != null)
                {
                    result = new UserModel
                    {
                        Id = user.Guid.Value,
                        Username = user.UserPrincipalName,
                        GivenName = user.GivenName ?? String.Empty,
                        Surname = user.Surname ?? String.Empty,
                        Email = user.EmailAddress ?? String.Empty,
                    };
                }
            }
            catch (Exception ex)
            {
                LogException(ex);
            }

            return result;
        }
        private UserModel GetUserModelFromPrincipal(UserPrincipal user)
        {
            UserModel result = null;

            try
            {
                if (user != null)
                {
                    result = new UserModel
                    {
                        Name = user.UserPrincipalName,
                        GivenName = user.GivenName ?? String.Empty,
                        Surname = user.Surname ?? String.Empty,
                        Email = user.EmailAddress ?? String.Empty,
                    };
                }
            }
            catch
            {
            }

            return result;
        }