Exemplo n.º 1
0
        public async Task <IActionResult> Register(string userName, string email, string password)
        {
            string cltMsgText = "";

            email = email.ToLower();

            if (sc.IsNullOrEmptyOWhiteSpacer(userName) || sc.validateEmail(email) || sc.validatePassword(password))
            {
                //   HttpContext.Response.StatusCode = StatusCodes.Status400BadRequest;
                return(BadRequest());
            }

            User user = await _dbRepo.GetItem <User>(email);

            if (user != null)
            {
                cltMsgText = $"User with email: {email} alredy exists!";
                // return StatusCode(409);
                return(new ObjectResult(new { token = "", msg = cltMsgText }));
            }

            string hpassword = _passwordHasher.GenerateIdentityV3Hash(password);

            user = new User {
                Name = userName, Email = email, Password = hpassword
            };
            await _dbRepo.AddItem(user, true);

            var atoken = GenerateJSONWebToken(user);

            return(new ObjectResult(new { token = atoken, msg = "" }));
        }
Exemplo n.º 2
0
        public async Task <ActionResult <AppResponse <Product> > > GetItem(string id)
        {
            AppResponse <Product> appResponse = null;

            try
            {
                Product entity = await dbRepo.GetItem <Product>(id);

                string msg = entity != null ? "" : "Product is not found";
                appResponse = new AppResponse <Product> {
                    Result = entity, ErrorMessage = msg
                };
            }
            catch (Exception e)
            {
                appResponse = new AppResponse <Product> {
                    ErrorMessage = e.Message
                };
            }

            return(appResponse);
        }