mirror of
https://github.com/jetzig-framework/jetzig.git
synced 2025-05-14 14:06:08 +00:00
Accept password at command line for auth user create
Intended for local development only
This commit is contained in:
parent
f9c6f9f38f
commit
c8ae44b508
@ -349,6 +349,9 @@ pub fn jetzigInit(b: *std.Build, exe: *std.Build.Step.Compile, options: JetzigIn
|
||||
if (b.option([]const u8, "auth_username", "Auth username")) |username| {
|
||||
run_auth_user_create_cmd.addArg(username);
|
||||
}
|
||||
if (b.option([]const u8, "auth_password", "Auth password")) |password| {
|
||||
run_auth_user_create_cmd.addArg(password);
|
||||
}
|
||||
|
||||
const exe_database = b.addExecutable(.{
|
||||
.name = "database",
|
||||
|
@ -60,13 +60,16 @@ pub fn run(
|
||||
std.debug.print("Missing argument. Expected an email/username parameter.\n", .{});
|
||||
break :blk error.JetzigCommandError;
|
||||
} else {
|
||||
try util.execCommand(allocator, &.{
|
||||
"zig",
|
||||
"build",
|
||||
util.environmentBuildOption(main_options.options.environment),
|
||||
try std.mem.concat(allocator, u8, &.{ "-Dauth_username=", sub_args[0] }),
|
||||
"jetzig:auth:user:create",
|
||||
});
|
||||
var argv = std.ArrayList([]const u8).init(allocator);
|
||||
try argv.append("zig");
|
||||
try argv.append("build");
|
||||
try argv.append(util.environmentBuildOption(main_options.options.environment));
|
||||
try argv.append(try std.mem.concat(allocator, u8, &.{ "-Dauth_username=", sub_args[0] }));
|
||||
if (sub_args.len > 1) {
|
||||
try argv.append(try std.mem.concat(allocator, u8, &.{ "-Dauth_password=", sub_args[1] }));
|
||||
}
|
||||
try argv.append("jetzig:auth:user:create");
|
||||
try util.execCommand(allocator, argv.items);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
@ -42,11 +42,22 @@ pub fn main() !void {
|
||||
const stdin = std.io.getStdIn();
|
||||
const reader = stdin.reader();
|
||||
|
||||
if (stdin.isTty()) std.debug.print("Enter password: ", .{});
|
||||
|
||||
const password = if (stdin.isTty() and args.len < 4) blk: {
|
||||
std.debug.print("Enter password: ", .{});
|
||||
var buf: [1024]u8 = undefined;
|
||||
if (try reader.readUntilDelimiterOrEof(&buf, '\n')) |input| {
|
||||
const password = std.mem.trim(u8, input, &std.ascii.whitespace);
|
||||
break :blk std.mem.trim(u8, input, &std.ascii.whitespace);
|
||||
} else {
|
||||
std.debug.print("Blank password. Exiting.\n", .{});
|
||||
return;
|
||||
}
|
||||
} else if (args.len >= 4)
|
||||
args[3]
|
||||
else {
|
||||
std.debug.print("Blank password. Exiting.\n", .{});
|
||||
return;
|
||||
};
|
||||
|
||||
const email = args[2];
|
||||
|
||||
try repo.insert(std.enums.nameCast(std.meta.DeclEnum(Schema), model), .{
|
||||
@ -54,9 +65,6 @@ pub fn main() !void {
|
||||
.password_hash = try hashPassword(allocator, password),
|
||||
});
|
||||
std.debug.print("Created user: `{s}`.\n", .{email});
|
||||
} else {
|
||||
std.debug.print("Blank password. Exiting.\n", .{});
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user