Beispiel #1
0
        private static bool TryToLogIn(DataModels.UserModel user)
        {
            bool result = false;

            var db = new ITAPPCarWorkshopServiceDBEntities();

            result = db.Users.Any(n => n.User_email.Equals(user.UserEmail) && n.User_password.Equals(user.UserPassword));

            return(result);
        }
Beispiel #2
0
        public static HttpResponseMessage Login(DataModels.UserModel user)
        {
            user.UserEmail = UserEmailAdjustment(user.UserEmail);

            var db = new ITAPPCarWorkshopServiceDBEntities();

            mutex.WaitOne();
            if (!CheckIfUserExistsPrivate(user.UserEmail))
            {
                mutex.ReleaseMutex();
                var response = new HttpResponseMessage(HttpStatusCode.Forbidden);
                response.Content = new StringContent("Account of given email address does not exists.");

                return(response);
            }

            if (TryToLogIn(user))
            {
                var    response    = new HttpResponseMessage(HttpStatusCode.OK);
                string TokenString = GenerateTokenForUser(user.UserEmail);
                int    userID      = GetUserIdByUserEmailPrivate(user.UserEmail);
                int    clientID    = -1;

                if (db.Client_Profiles.Any(n => n.User_ID == userID))
                {
                    clientID = db.Client_Profiles.First(n => n.User_ID == userID).Client_ID;
                }

                mutex.ReleaseMutex();

                var ResponseContentAsModel = new ITAPP_CarWorkshopService.AdditionalModels.LoginResponse()
                {
                    Token    = TokenString,
                    UserID   = userID,
                    ClientID = clientID
                };

                var ResponseContentAsJSON = JsonConvert.SerializeObject(ResponseContentAsModel);
                response.Content = new StringContent(ResponseContentAsJSON);

                return(response);
            }
            else
            {
                mutex.ReleaseMutex();
                var response = new HttpResponseMessage(HttpStatusCode.Forbidden);
                response.Content = new StringContent("Wrong password");

                return(response);
            }
        }
        public HttpResponseMessage RegisterUser([FromBody] DataModels.UserModel NewUser)
        {
            if (UserManager.RegisterUser(NewUser))
            {
                var response = new HttpResponseMessage(HttpStatusCode.OK);
                response.Content = new StringContent("User succesfully added to DB.");

                return(response);
            }
            else
            {
                var response = new HttpResponseMessage(HttpStatusCode.Forbidden);
                response.Content = new StringContent("User was not added to DB.");

                return(response);
            }
        }
Beispiel #4
0
        public static bool RegisterUser(DataModels.UserModel UserModel)
        {
            UserModel.UserEmail = UserEmailAdjustment(UserModel.UserEmail);

            var UserEntity = UserModel.MakeUserEntityFromUserModel();

            var db = new ITAPPCarWorkshopServiceDBEntities();

            mutex.WaitOne();
            if (CheckIfUserExistsPrivate(UserModel.UserEmail))
            {
                mutex.ReleaseMutex();
                return(false);
            }

            db.Users.Add(UserEntity);
            db.SaveChanges();

            mutex.ReleaseMutex();

            return(true);
        }
Beispiel #5
0
        public static List <DataModels.UserModel> GetUser(int userId)
        {
            mutex.WaitOne();

            if (!CheckIfUserExistsPrivate(userId))
            {
                mutex.ReleaseMutex();
                return(null);
            }

            var db = new ITAPPCarWorkshopServiceDBEntities();

            DataModels.UserModel user = new DataModels.UserModel(db.Users.FirstOrDefault(n => n.User_ID == userId));
            mutex.ReleaseMutex();

            user.UserPassword = "******";

            var list = new List <DataModels.UserModel>();

            list.Add(user);

            return(list);
        }
        public HttpResponseMessage Login([FromBody] DataModels.UserModel user)
        {
            var response = UserManager.Login(user);

            return(response);
        }