Beispiel #1
0
        public async Task <HttpResponseMessage> Post([FromBody] SystemUser user)
        {
            try
            {
                if (SystemUser.UserExists(user.Username))
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, new { message = "Username already used" }));
                }

                user.Password = SystemUser.Base64Encode(user.Password);
                var result = await Model.SystemUser.Insert(user);

                result.GenerateAuthToken();
                ApplicationContext.AddAuthenticatedUser(result);
                return(Request.CreateResponse(HttpStatusCode.Created, result));
            }
            catch (Exception ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex));
            }
        }