Add SetPasswordJob in Users module, hook it all up.
This commit is contained in:
parent
8e3002bfbb
commit
b111027d57
@ -1,15 +1,21 @@
|
||||
include_directories( ${PROJECT_BINARY_DIR}/src/libcalamaresui )
|
||||
|
||||
list( APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules" )
|
||||
find_package( Crypt )
|
||||
|
||||
calamares_add_plugin( users
|
||||
TYPE viewmodule
|
||||
EXPORT_MACRO PLUGINDLLEXPORT_PRO
|
||||
CONFIG_FILE module.conf
|
||||
SOURCES
|
||||
CreateUserJob.cpp
|
||||
SetPasswordJob.cpp
|
||||
UsersViewStep.cpp
|
||||
UsersPage.cpp
|
||||
UI
|
||||
page_usersetup.ui
|
||||
LINK_LIBRARIES
|
||||
calamaresui
|
||||
${CRYPT_LIBRARIES}
|
||||
SHARED_LIB
|
||||
)
|
||||
|
68
src/modules/users/SetPasswordJob.cpp
Normal file
68
src/modules/users/SetPasswordJob.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Calamares is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <SetPasswordJob.h>
|
||||
|
||||
#include "JobQueue.h"
|
||||
#include "GlobalStorage.h"
|
||||
#include "utils/Logger.h"
|
||||
#include "utils/CalamaresUtilsSystem.h"
|
||||
|
||||
#include <QDir>
|
||||
|
||||
#include <crypt.h>
|
||||
|
||||
|
||||
SetPasswordJob::SetPasswordJob( const QString& userName, const QString& newPassword )
|
||||
: Calamares::Job()
|
||||
, m_userName( userName )
|
||||
, m_newPassword( newPassword )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
QString
|
||||
SetPasswordJob::prettyName() const
|
||||
{
|
||||
return tr( "Set password for user %1" ).arg( m_userName );
|
||||
}
|
||||
|
||||
|
||||
Calamares::JobResult
|
||||
SetPasswordJob::exec()
|
||||
{
|
||||
Calamares::GlobalStorage* gs = Calamares::JobQueue::instance()->globalStorage();
|
||||
QDir destDir( gs->value( "rootMountPoint" ).toString() );
|
||||
if ( !destDir.exists() )
|
||||
return Calamares::JobResult::error( tr( "Bad destination system path." ),
|
||||
tr( "rootMountPoint is %1" ).arg( destDir.absolutePath() ) );
|
||||
|
||||
QByteArray data = crypt( m_newPassword.toLatin1(), QString( "$6$%1$" ).arg( m_userName ).toLatin1() );
|
||||
|
||||
int ec = CalamaresUtils::chrootCall( { "usermod",
|
||||
"-p",
|
||||
QString::fromLatin1( data ),
|
||||
m_userName } );
|
||||
if ( ec )
|
||||
return Calamares::JobResult::error( tr( "Cannot set password for user %1." )
|
||||
.arg( m_userName ),
|
||||
tr( "usermod terminated with error code %1." )
|
||||
.arg( ec ) );
|
||||
|
||||
return Calamares::JobResult::ok();
|
||||
}
|
39
src/modules/users/SetPasswordJob.h
Normal file
39
src/modules/users/SetPasswordJob.h
Normal file
@ -0,0 +1,39 @@
|
||||
/* === This file is part of Calamares - <http://github.com/calamares> ===
|
||||
*
|
||||
* Copyright 2014, Teo Mrnjavac <teo@kde.org>
|
||||
*
|
||||
* Calamares is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Calamares is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Calamares. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef SETPASSWORDJOB_H
|
||||
#define SETPASSWORDJOB_H
|
||||
|
||||
#include <Job.h>
|
||||
|
||||
|
||||
class SetPasswordJob : public Calamares::Job
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
SetPasswordJob( const QString& userName,
|
||||
const QString& newPassword );
|
||||
QString prettyName() const override;
|
||||
Calamares::JobResult exec() override;
|
||||
|
||||
private:
|
||||
QString m_userName;
|
||||
QString m_newPassword;
|
||||
};
|
||||
|
||||
#endif /* SETPASSWORDJOB_H */
|
@ -22,6 +22,10 @@
|
||||
|
||||
#include "UsersPage.h"
|
||||
#include "ui_page_usersetup.h"
|
||||
#include "CreateUserJob.h"
|
||||
#include "SetPasswordJob.h"
|
||||
#include "JobQueue.h"
|
||||
#include "GlobalStorage.h"
|
||||
|
||||
#include <QBoxLayout>
|
||||
#include <QLabel>
|
||||
@ -70,6 +74,34 @@ UsersPage::isReady()
|
||||
}
|
||||
|
||||
|
||||
QList< Calamares::job_ptr >
|
||||
UsersPage::createJobs()
|
||||
{
|
||||
QList< Calamares::job_ptr > list;
|
||||
if ( !isReady() )
|
||||
return list;
|
||||
|
||||
Calamares::Job* j;
|
||||
j = new CreateUserJob( ui->textBoxUsername->text(),
|
||||
QString(),
|
||||
ui->checkBoxLoginAuto->isChecked() );
|
||||
list.append( Calamares::job_ptr( j ) );
|
||||
|
||||
j = new SetPasswordJob( ui->textBoxUsername->text(),
|
||||
ui->textBoxUserPassword->text() );
|
||||
list.append( Calamares::job_ptr( j ) );
|
||||
|
||||
j = new SetPasswordJob( "root",
|
||||
ui->textBoxRootPassword->text() );
|
||||
list.append( Calamares::job_ptr( j ) );
|
||||
|
||||
Calamares::JobQueue::instance()->
|
||||
globalStorage()->insert( "hostname", ui->textBoxHostname->text() );
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
UsersPage::onUsernameTextChanged( const QString& textRef )
|
||||
{
|
||||
|
@ -23,6 +23,8 @@
|
||||
#ifndef USERSPAGE_H
|
||||
#define USERSPAGE_H
|
||||
|
||||
#include "Typedefs.h"
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
namespace Ui {
|
||||
@ -38,6 +40,8 @@ public:
|
||||
|
||||
bool isReady();
|
||||
|
||||
QList< Calamares::job_ptr > createJobs();
|
||||
|
||||
protected slots:
|
||||
void onUsernameTextChanged( const QString& );
|
||||
void onHostnameTextChanged( const QString& );
|
||||
|
@ -87,6 +87,15 @@ UsersViewStep::isAtEnd() const
|
||||
QList< Calamares::job_ptr >
|
||||
UsersViewStep::jobs() const
|
||||
{
|
||||
return QList< Calamares::job_ptr >();
|
||||
return m_jobs;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
UsersViewStep::onLeave()
|
||||
{
|
||||
m_jobs.clear();
|
||||
|
||||
m_jobs.append( m_widget->createJobs() );
|
||||
}
|
||||
|
||||
|
@ -51,8 +51,11 @@ public:
|
||||
|
||||
QList< Calamares::job_ptr > jobs() const override;
|
||||
|
||||
void onLeave() override;
|
||||
|
||||
private:
|
||||
UsersPage* m_widget;
|
||||
QList< Calamares::job_ptr > m_jobs;
|
||||
};
|
||||
|
||||
#endif // USERSPAGEPLUGIN_H
|
||||
|
Loading…
Reference in New Issue
Block a user