Exemple #1
0
        public async Task <IActionResult> InviteUser(InviteViewModel inviteViewModel)
        {
            Invite invite = new Invite();

            invite.Email          = inviteViewModel.Email;
            invite.FacilityId     = inviteViewModel.FacilityId;
            invite.OrganizationId = inviteViewModel.organization_id;
            invite.RoleId         = inviteViewModel.RoleId;
            invite.CreationDate   = DateTime.Now;
            var InvitedUser = await _inviteservice.InsertInvite(invite);

            var claimsIdentity = new ClaimsIdentity(new List <Claim>()
            {
                new Claim(ClaimTypes.Name, InvitedUser.Email),
                new Claim(ClaimTypes.NameIdentifier, InvitedUser.Id.ToString()),
            }, "Identity.Application");

            var token = _passwordService.CreateAccessToken(_passwordService.CreateJwtClaims(claimsIdentity));

            var baseUrl = string.Format("{0}://{1}{2}/", Request.Scheme, Request.Host, Request.PathBase) + "api/User/GetInvitedUser?token=" + token;
            //api / User / GetInvitedUser ? id = 4
            var organisation = await _organizationService.GetOrganization(inviteViewModel.organization_id);

            var emailBody     = string.Format(AppConstants.InviteEmailTemplate, baseUrl);
            var emailsubjects = string.Format(AppConstants.InviteEmailSubject, organisation.Name);
            var apiKey        = AppConstants.SendGridKey;
            var result        = await _sendEmailService.send_email_sendgrid(apiKey, invite.Email, emailsubjects, emailBody);

            return(Ok(result));
        }
Exemple #2
0
        public IActionResult request_access(string encodedDeviceId)
        {
            try
            {
                string message;
                string decodedDeviceId = "";
                if (!String.IsNullOrEmpty(encodedDeviceId))
                {
                    try
                    {
                        byte[] deviceIdBytes = Convert.FromBase64String(encodedDeviceId);
                        decodedDeviceId = Encoding.UTF8.GetString(deviceIdBytes);
                    }
                    catch (Exception) //CREATE CUSTOM EXCEPTION FOR INVALID ENCODED DEVICE ID
                    {
                        message = "INVALID_DEVICEID";
                        var _response = new DeviceApiResponse <bool>(message);
                        return(BadRequest(_response));
                    }

                    message = "REQUEST_ACCESS_SUCCESS";
                    var claimsIdentity = new ClaimsIdentity(new List <Claim>()
                    {
                        new Claim(ClaimTypes.NameIdentifier, decodedDeviceId)
                    }, "Identity.Application");

                    var token    = _passwordService.CreateAccessToken(_passwordService.CreateJwtClaims(claimsIdentity));
                    var response = new DeviceApiResponse <string>(token, message);
                    return(Ok(response));
                }
                else
                {
                    message = "NULL_PARAMETER";
                    var response = new DeviceApiResponse <bool>(message);
                    return(BadRequest(response));
                }
            }
            catch (Exception ex)
            {
                string message  = "ERROR";
                var    response = new DeviceApiResponse <Exception>(ex, message);
                return(StatusCode(500, response));
            }
        }