Exemplo n.º 1
0
        public bool SaveJwt(string token, Guid uId)
        {
            var claimJwt = new ClaimJwt
            {
                Jwt    = token,
                UserId = uId
            };

            try
            {
                var claimJwtExists = _ctx.ClaimJwts.FirstOrDefault(x => x.UserId == uId);
                if (claimJwtExists == null)
                {
                    _ctx.Add(claimJwt);
                }
                else
                {
                    claimJwtExists.UserId = uId;
                    claimJwtExists.Jwt    = token;

                    _ctx.Entry(claimJwtExists).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
                }
                _ctx.SaveChanges();
            }
            catch (Exception e)
            {
                var error = e;
                throw;
            }


            return(true);
        }
Exemplo n.º 2
0
        public ActionResult register(LoginDto newUser)
        {
            User user = null;

            if (!String.IsNullOrWhiteSpace(newUser.NationalCode) &&
                !String.IsNullOrWhiteSpace(newUser.Password) &&
                UserUniqe(newUser.NationalCode))
            {
                byte[] passwordHash, passwordSalt;
                AuthHelper.CreatePasswordHash(newUser.Password, out passwordHash, out passwordSalt);
                user = new User
                {
                    NationalCode = newUser.NationalCode,
                    PasswordHash = passwordHash,
                    PasswordSalt = passwordSalt
                };

                _ctx.Add(user);
                _ctx.SaveChanges();
                return(Ok(user));
            }

            return(BadRequest("email is already taken"));
        }