Added new user setup

This commit is contained in:
Kim 2023-10-23 16:19:03 +02:00
parent d402714b59
commit 93b56bf1cc
4 changed files with 53 additions and 6 deletions

View File

@ -21,11 +21,6 @@ jobs:
- run: |
npm --prefix ${{ gitea.workspace }}/typescript/frontend-marios2 install
npm --prefix ${{ gitea.workspace }}/typescript/frontend-marios2 run build
- uses: burnett01/rsync-deployments@6.0.0
- run: |
cd ${{ gitea.workspace }}
rsync -av ./csharp/App/Backend/bin/Release/net6.0/linux-x64/publish/ ubuntu@${{ secrets.STAGING_SSH_HOST }}:~/backend
rsync -av ./typescript/frontend-marios2/* ubuntu@${{ secrets.STAGING_SSH_HOST }}:~/frontend/
- name: Configure SSH
run: |
mkdir -p ~/.ssh/
@ -43,6 +38,9 @@ jobs:
SSH_KEY: ${{ secrets.STAGING_SSH_KEY }}
SSH_HOST: ${{ secrets.STAGING_SSH_HOST }}
- run: |
cd ${{ gitea.workspace }}
rsync -av ./csharp/App/Backend/bin/Release/net6.0/linux-x64/publish/ staging:~/backend
rsync -av ./typescript/frontend-marios2/* staging:~/frontend/
ssh staging 'sudo systemctl restart backend'
ssh staging 'sudo cp -rf ~/frontend/build/* /var/www/html/monitor.innov.energy/html/'
ssh staging 'sudo npm install -g serve'

View File

@ -257,7 +257,10 @@ public class Controller : ControllerBase
[HttpPost(nameof(CreateUser))]
public ActionResult<User> CreateUser([FromBody] User newUser, Token authToken)
{
return Db.GetSession(authToken).Create(newUser)
var session = new Session(newUser);
var res = Db.Create(session);
return res && Db.GetSession(authToken).Create(newUser) && Db.SendNewUserEmail(newUser, session.Token)
? newUser.HidePassword()
: Unauthorized() ;
}
@ -491,6 +494,17 @@ public class Controller : ControllerBase
return Redirect($"https://monitor.innov.energy/?username={user.Email}");
}
[HttpGet(nameof(NewUserLogin))]
public ActionResult<Object> NewUserLogin(Token token)
{
var user = Db.GetSession(token)?.User;
if (user is null)
return Unauthorized();
// Console.WriteLine("HELP");
return Redirect($"https://monitor.innov.energy/?username={user.Email}");
}
}

View File

@ -177,6 +177,11 @@ public static partial class Db
return Email.Email.SendPasswordResetMessage(user, sessionToken);
}
public static Boolean SendNewUserEmail(User user, String sessionToken)
{
return Email.Email.SendNewUserMessage(user, sessionToken);
}
public static Boolean DeleteUserPassword(User user)
{
user.Password = "";

View File

@ -51,4 +51,34 @@ public static class Email
return false;
}
}
[UnconditionalSuppressMessage("Trimming", "IL2026:Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code", Justification = "<Pending>")]
public static Boolean SendNewUserMessage (User emailRecipientUser, String token)
{
var config = JsonSerializer.Deserialize<SmtpConfig>(File.OpenRead("./Resources/smtpConfig.json"))!;
//todo am I right?
const String resetLink = "https://monitor.innov.energy/api/NewUserLogin";
var mailer = new Mailer();
try
{
mailer.From("InnovEnergy", "noreply@innov.energy");
mailer.To(emailRecipientUser.Name, emailRecipientUser.Email);
mailer.Subject("Your new Innovenergy-Account");
mailer.Body("Dear " + emailRecipientUser.Name
+ "\n To set your password and log in to your Innovenergy-Account open this link:"
+ resetLink + "?token="
+ token);
return mailer.SendEmailUsingSmtpConfig(config);
}
catch (Exception)
{
return false;
}
}
}