public async Task <IActionResult> CreateDesktop(DesktopCreateModel m)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            var response = await _dService.CreateDesktopClientAsync(m);

            return(Ok(response));
        }
Exemple #2
0
        public async Task <IActionResult> Login(SyncLoginModel mod)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            // Password Hash
            var currentUser = _context.Users.Where(x => x.Email.ToUpper().CompareTo(mod.EmailAddress.ToUpper()) == 0 && x.Status == true).FirstOrDefault();

            if (currentUser == null || !Hash.Validate(mod.Password, currentUser.salt, currentUser.PasswordHash))
            {
                return(BadRequest(new { message = "Your login input is incorrect" }));
            }

            var d = await _context.DesktopClients.Where(x => mod.ClientName.ToUpper().CompareTo(x.ClientName.ToUpper()) == 0 &&
                                                        mod.ClientMacAddress.ToUpper().CompareTo(x.ClientMacAddress.ToUpper()) == 0 &&
                                                        mod.ClientType.ToUpper().CompareTo(x.ClientType.ToUpper()) == 0).FirstOrDefaultAsync();

            //gets the type of the user
            var type = _oService.Strip(currentUser.GetType().ToString());

            if (d == null)
            {
                var dc = new DesktopCreateModel()
                {
                    ClientMacAddress = mod.ClientMacAddress,
                    ClientName       = mod.ClientName,
                    ClientType       = mod.ClientType,
                };
                d = await _dService.CreateDesktopClientAsync(dc);
            }

            var token = await _tokGen.GenerateToken(d, currentUser.Id, type);


            return(Ok(token));
        }