예제 #1
0
        //Local register
        //Input: registerDTO
        //Output: clientId
        public static string registerClientLocal(registerDTO body)
        {
            SwapDbConnection db     = new SwapDbConnection();
            client           client = db.clients.FirstOrDefault(c => c.email == body.email && (c.platform == "local"));
            string           id     = "";

            if (client == null)
            {
                id = IdService.generateID("client");
                HashSalt hs = HashSalt.GenerateSaltedHash(body.password);

                client new_client = new client()
                {
                    client_id     = id,
                    email         = body.email,
                    birthday_date = body.birthday,
                    creation_date = DateTime.Now,
                    first_name    = body.first_name,
                    last_login    = DateTime.Now,
                    last_name     = body.last_name,
                    phone         = body.phone,
                    sex           = body.sex,
                    password      = hs.Hash,
                    salt          = hs.Salt,
                    platform      = "local"
                };

                db.clients.Add(new_client);
                db.SaveChanges();
            }
            return(id);
        }
예제 #2
0
 public HttpResponseMessage register([FromBody] registerDTO body)
 {
     try
     {
         string id = clientService.registerClientLocal(body);
         if (id == "")
         {
             return(Request.CreateResponse(HttpStatusCode.BadRequest, "This Email is in used."));
         }
         return(Request.CreateResponse(HttpStatusCode.OK, JWTGetToken.getToken(id, body.email, "client")));
     }
     catch (Exception e)
     {
         return(Request.CreateResponse(HttpStatusCode.InternalServerError, "There was an InternalServerError: " + e));
     }
 }
        public async Task <ActionResult <String> > Register([FromBody] registerDTO model)
        {
            IdentityUser user = new IdentityUser {
                UserName = model.Email, Email = model.Email
            };
            BUser bUser = new BUser {
                Email = model.Email, FirstName = model.FirstName, LastName = model.LastName
            };
            var result = await _userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                _bUserRepository.Add(bUser);
                _bUserRepository.SaveChanges();
                string token = GetToken(user);
                return(Created("", token));
            }

            return(BadRequest("Something went wrong"));
        }