|
|
@@ -1,5 +1,7 @@
|
|
|
using InvercargillSql.Orm;
|
|
|
using Spry.Authorisation;
|
|
|
+using Invercargill.Expressions;
|
|
|
+using Invercargill;
|
|
|
using Inversion;
|
|
|
|
|
|
namespace Spry.Authentication {
|
|
|
@@ -12,7 +14,7 @@ namespace Spry.Authentication {
|
|
|
|
|
|
public async AuthorisationToken? authenticate_user(string username, string password) throws Error {
|
|
|
var user = yield db.query<UserProjection>()
|
|
|
- .where(@"username == \"$(username)\"")
|
|
|
+ .where_expr(ExpressionParser.parse_with_params("username == $0", new NativeElement<string>(username)))
|
|
|
.first_async();
|
|
|
|
|
|
if(!Sodium.PasswordHashing.check(user.password_hash, password)){
|
|
|
@@ -41,7 +43,7 @@ namespace Spry.Authentication {
|
|
|
|
|
|
public async void set_password(int64 user_id, string password) throws Error {
|
|
|
var user = yield db.query<UserEntity>()
|
|
|
- .where(@"id == $user_id")
|
|
|
+ .where_expr(ExpressionParser.parse_with_params("id == $0", new NativeElement<int64?>(user_id)))
|
|
|
.first_async();
|
|
|
|
|
|
user.password_hash = Sodium.PasswordHashing.hash(password);
|
|
|
@@ -50,20 +52,33 @@ namespace Spry.Authentication {
|
|
|
}
|
|
|
|
|
|
public async UserEntity alter_user(int64 user_id, string username, string email, string forename, string surname, DateTime date_of_birth, bool enabled) throws Error {
|
|
|
- var user = new UserEntity() {
|
|
|
- username = username,
|
|
|
- email = email,
|
|
|
- forename = forename,
|
|
|
- surname = surname,
|
|
|
- date_of_birth = date_of_birth,
|
|
|
- modified = new DateTime.now_utc(),
|
|
|
- enabled = enabled,
|
|
|
- };
|
|
|
+ var user = yield db.query<UserEntity>()
|
|
|
+ .where_expr(ExpressionParser.parse_with_params("id == $0", new NativeElement<int64?>(user_id)))
|
|
|
+ .first_async();
|
|
|
+
|
|
|
+ user.username = username;
|
|
|
+ user.email = email;
|
|
|
+ user.forename = forename;
|
|
|
+ user.surname = surname;
|
|
|
+ user.date_of_birth = date_of_birth;
|
|
|
+ user.modified = new DateTime.now_utc();
|
|
|
+ user.enabled = enabled;
|
|
|
|
|
|
db.update<UserEntity>(user);
|
|
|
return user;
|
|
|
}
|
|
|
|
|
|
+ public async void set_user_enabled(int64 user_id, bool enabled) throws Error {
|
|
|
+ var user = yield db.query<UserEntity>()
|
|
|
+ .where_expr(ExpressionParser.parse_with_params("id == $0", new NativeElement<int64?>(user_id)))
|
|
|
+ .first_async();
|
|
|
+
|
|
|
+ user.modified = new DateTime.now_utc();
|
|
|
+ user.enabled = enabled;
|
|
|
+
|
|
|
+ db.update<UserEntity>(user);
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
}
|