示例#1
0
        public RegistrationResponse Registration(ISession session, RegistrationRequest request)
        {
            var response = request.CreateResponse <RegistrationResponse>();

            if (string.IsNullOrWhiteSpace(request.DeviceId) ||
                request.UserId < 1 ||
                request.PublicKey.IsNullOrEmpty())
            {
                response.Success = false;
                return(response);
            }

            _devicesRepository.AddDevice(request.UserId, request.DeviceId);
            _devicesRepository.SetPublicKeyForDevice(request.DeviceId, request.PublicKey);

            return(response);
        }
示例#2
0
        public ActionResult <Device> PostDevice([FromBody] DeviceModel deviceModel)
        {
            ExtractToken();

            if (accessTokenHeader != null)
            {
                var token = appUserTokensRepository.Get(accessTokenHeader);
                if (token != null)
                {
                    var device = new Device
                    {
                        AppUserId   = token.AppUserId,
                        Name        = deviceModel.Name,
                        Description = deviceModel.Description
                    };

                    devicesRepository.AddDevice(device);
                    return(device);
                }
            }

            return(Unauthorized());
        }