using Astralis; using Inversion; namespace Spry.Authentication { public class UserEditComponent : Component { public int user_id { get; set; } public string username { get; set; } public UserProjection user { get; set; } public override string markup { get { return """
"""; }} private UserService user_service = inject(); private HttpContext http_context = inject(); public async override void handle_action (string action) throws Error { var form = yield Astralis.FormDataParser.parse (http_context.request.request_body, http_context.request.content_type); var dob_strs = form.get_field ("date_of_birth").split("-"); var dob = new DateTime(new TimeZone.utc (), int.parse(dob_strs[0]), int.parse(dob_strs[1]), int.parse(dob_strs[2]), 0, 0, 0); yield user_service.alter_user (user_id, username, form.get_field ("email"), form.get_field ("forename"), form.get_field ("surname"), dob, true); var new_password = form.get_field ("new_password"); if(new_password != null && new_password != "") { yield user_service.set_password (user_id, new_password); } response.set_header ("HX-Refresh", "true"); response.skip_content (); } } }