aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs
diff options
context:
space:
mode:
authorRoy Ben Shabat <Roy.mail.net@gmail.com>2020-05-11 03:37:33 +0300
committerRoy Ben Shabat <Roy.mail.net@gmail.com>2020-05-11 03:37:33 +0300
commitd4adb3a3faa36b4500c17e661e09ec2af338b353 (patch)
treee31967e0e9b9dd198c8bf646c1c3c22599badada /Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs
parent9ead141002c63c1a44d7851fa4a4a1902c0bfe89 (diff)
downloadTango-d4adb3a3faa36b4500c17e661e09ec2af338b353.tar.gz
Tango-d4adb3a3faa36b4500c17e661e09ec2af338b353.zip
User invitation via Email !
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs')
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs80
1 files changed, 63 insertions, 17 deletions
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs
index 7bf420df9..01878f16a 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs
@@ -1,10 +1,13 @@
-using System;
+using SendGrid;
+using SendGrid.Helpers.Mail;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Security.Authentication;
using System.Threading.Tasks;
+using System.Web;
using System.Web.Http;
using Tango.BL;
using Tango.BL.Builders;
@@ -78,22 +81,6 @@ namespace Tango.MachineService.Controllers
AccessTokenExpiration = accessToken.ExpiresOn.UtcDateTime
};
-
- //Enforce Machine Studio Version ?
- //if (MachineServiceConfig.ENFORCE_MACHINE_STUDIO_VERSION)
- //{
- // using (var db = ObservablesContextHelper.CreateContext())
- // {
- // var latest_version = db.MachineStudioVersions.ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault();
-
- // if (latest_version != null && Version.Parse(latest_version.Version) != client_version)
- // {
- // versionChangeRequired = true;
- // requiredVersion = latest_version.Version;
- // }
- // }
- //}
-
//Return data source
return new LoginResponse()
{
@@ -230,5 +217,64 @@ namespace Tango.MachineService.Controllers
Expiration = accessToken.ExpiresOn.UtcDateTime,
};
}
+
+ [HttpPost]
+ [JwtTokenFilter]
+ public UserInvitationEmailResponse SendUserInvitationEmail(UserInvitationEmailRequest request)
+ {
+ using (ObservablesContext db = ObservablesContextHelper.CreateContext())
+ {
+ if (!db.Users.Any(x => x.Email.ToLower() == request.Email.ToLower()))
+ {
+ throw new InvalidOperationException("User not found.");
+ }
+ }
+
+ var client = new SendGridClient(MachineServiceConfig.SEND_GRID_API_KEY);
+ SendGridMessage msg = new SendGridMessage();
+ msg.SetFrom("info@twine-s.com", "Twine Solutions LTD");
+ msg.AddTo(request.Email);
+ msg.Subject = "Welcome To Tango FSE";
+ msg.SetTemplateId("d-2af42ed0ea3c44b3abaa61016223555a");
+
+ var dynamicTemplateData = new
+ {
+ DownloadUrl = $"{request.MachineServiceAddress}/fse",
+ request.FullName,
+ request.Password,
+ };
+
+ msg.SetTemplateData(dynamicTemplateData);
+
+ var result = client.SendEmailAsync(msg).GetAwaiter().GetResult();
+
+ if (result.StatusCode != HttpStatusCode.Accepted)
+ {
+ throw new HttpException(result.StatusCode.ToString());
+ }
+
+ return new UserInvitationEmailResponse();
+ }
+
+ [HttpPost]
+ public ForgotPasswordResponse SendForgotPasswordEmail(ForgotPasswordRequest request)
+ {
+ using (ObservablesContext db = ObservablesContextHelper.CreateContext())
+ {
+ if (!db.Users.Any(x => x.Email.ToLower() == request.Email.ToLower()))
+ {
+ throw new InvalidOperationException("User not found.");
+ }
+ }
+
+ //TODO: create a special link that when surfed will reset the password for the user and display the new temp password.
+ return new ForgotPasswordResponse();
+ }
+
+ [HttpGet]
+ public String ResetPassword(String guid)
+ {
+ return String.Empty; //Reset the password and return the new temp password.
+ }
}
}