Exemplo n.º 1
0
        public IActionResult AddCompany(AddComanyViewModel addComanyViewModel)
        {
            try
            {
                var token = _companyRepository.AddNewCompany(addComanyViewModel);
                return(Ok(token));
            }
            catch (Exception e)
            {
                return(Ok(e));

                throw;
            }
        }
Exemplo n.º 2
0
        public IHttpActionResult Register(JObject dataToRegister)
        {
            if (dataToRegister["companyName"] == null || dataToRegister["newUser"] == null)
            {
                return(new ResponseMessageResult(Request.CreateResponse(HttpStatusCode.Forbidden)));
            }
            var companyName    = dataToRegister["companyName"].ToObject <string>();
            var userToRegister = dataToRegister["newUser"].ToObject <User>();

            var stringsToCheck = new List <string>()
            {
                companyName,
                userToRegister.Username,
                userToRegister.FirstName,
                userToRegister.LastName,
                userToRegister.Password
            };

            if (_userRepository.DoesUsernameExist(userToRegister.Username))
            {
                return(new ResponseMessageResult(Request.CreateResponse(HttpStatusCode.Forbidden)));
            }
            if (stringsToCheck.Any(str => str == null || !char.IsLetter(str[0]) || !str.All(c => char.IsLetterOrDigit(c) || c == ' ') || str.Length < 3))
            {
                return(new ResponseMessageResult(Request.CreateResponse(HttpStatusCode.Forbidden)));
            }
            if (!Regex.IsMatch(userToRegister.Username, @"^[a-z0-9]+$"))
            {
                return(new ResponseMessageResult(Request.CreateResponse(HttpStatusCode.Forbidden)));
            }
            if (userToRegister.Password.Length < 6 || !Regex.IsMatch(userToRegister.Password, @"^[a-zA-Z0-9]+$"))
            {
                return(new ResponseMessageResult(Request.CreateResponse(HttpStatusCode.Forbidden)));
            }

            var companyId = _companyRepository.AddNewCompany(companyName);

            userToRegister.CompanyId = companyId;
            userToRegister.Password  = HashHelper.HashPassword(userToRegister.Password);
            _userRepository.AddUser(userToRegister);
            return(Ok(true));
        }